entry data via Smarty parsing plugin

Creating and modifying plugins.
Post Reply
peggylon
Regular
Posts: 51
Joined: Tue Jul 01, 2008 6:32 pm
Location: Berlin
Contact:

entry data via Smarty parsing plugin

Post by peggylon »

Hi,

in order to use the entry's url for a piece of code I regularly copy-paste into my posts, I installed the Smarty Parsing plugin. In the entry body box I added the line

Code: Select all

Test: {$entry.title}


for testing purpose. This results in just 'Test: '. The entry in question does have a title and is online.
I also tried {$GLOBALS|@print_r} and {$eventData|@print_r} as suggested in other forum topics related to Smarty parsing plugin. Both result in '1'.

Am I missing something or are entry variables called differently from within the entry body? Is it necessary to change my templates config.inc.php, even if there is no {php} involved?

BTW, this is a very helpful forum and thanks for the great work!
----------
peggylon aka multikulinaria http://www.multikulinarisch.es
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: entry data via Smarty parsing plugin

Post by garvinhicking »

Hi!

The Smarty Markup plugin executes and evalutes the entry within its own context; it does not have any outside-scope variables available, apart from global variables; {$blogTitle} for example should be set.

This is due to the content being evaluated within a plugin, and then passing the whole Smarty result as HTML to the entries.tpl template - at this point, Smarty is already rendered, so the blog entry body will never know of its surrounding.

However, you should also be able to utilize {$smartymarkup_eventData|@print_r} to see the actual event data from within the plugin. Maybe this helps?

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
peggylon
Regular
Posts: 51
Joined: Tue Jul 01, 2008 6:32 pm
Location: Berlin
Contact:

Re: entry data via Smarty parsing plugin

Post by peggylon »

Thanks Garvin, that's the way to go. At least for most of the current entry's data.

Code: Select all

{$smartymarkup_eventData.title} 
outputs the desired title.

What the $smartymarkup_eventData array does not contain and what I'm after is the current entry's url, though.

Code: Select all

{$smartymarkup_eventData.link}
returns no result.

I guess to retrieve the url of the entry in making, I would have to adopt the same functionlity that actually creates the link. Any idea of how the existing functionality could be used? Otherwise I might have to add a modifier, right?

cheers Peggy
----------
peggylon aka multikulinaria http://www.multikulinarisch.es
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Smarty parsing plugin

Post by Timbalu »

how about

Code: Select all

{$serendipityBaseURL}archives/{$smartymarkup_eventData.id}-{$smartymarkup_eventData.title|replace:' ':'-'}.html
edit:
better use

Code: Select all

{$serendipityBaseURL}archives/{$smartymarkup_eventData.id}-{$smartymarkup_eventData.title|escape:"url"}.html
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: entry data via Smarty parsing plugin

Post by garvinhicking »

Hi!

Hm, the best would be to call the serendipity_archiveURL() functionality; I don'T think a smarty modifier exists for that yet.

You could add an easy wrapper inside the config.inc.php file of your template, like

Code: Select all

$serendipity['smarty']->register_modifier('serendipity_archiveURL', 'serendipity_archiveURL');
and then use in your entry smarty code:

Code: Select all

{$smartymarkup_eventData.id|@serendipity_archiveURL:$smartymarkup_eventData.title}
This is untested, but I hope it works *g*

Timbalus option is also a variant, however it hardcodes the permalink URL structure, so when you change it, you need to change the code...

(Of course, whatever you're planning to do might be worth evaluating if creating a serendipity PHP event plugin might be the better way; there you have the whole s9y API available to perform output, and might simply listen to the "entry_display" event hook...?)

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
peggylon
Regular
Posts: 51
Joined: Tue Jul 01, 2008 6:32 pm
Location: Berlin
Contact:

Re: entry data via Smarty parsing plugin

Post by peggylon »

Timbalu, I thought of that option. But since replacing takes into account more options as specified in serendipity_local_config.inc.php (which don't really work, but that's another story)

Code: Select all

$GLOBALS['i18n_filename_from'] = array(' ', '!', '%', '_', '+', ',', ';', '.', ':', '?');
$GLOBALS['i18n_filename_to'] = array('', '','','','', '','','','-'.'');
and I would want to the link to be exactly as the title link created by s9y, I'd prefer a dynamic approach, using the modifier.
Garvin, I tryed what you suggested. It works like a charme.

Thank you both!
----------
peggylon aka multikulinaria http://www.multikulinarisch.es
MaryRowley
Posts: 1
Joined: Thu Mar 07, 2013 12:29 pm

Re: entry data via Smarty parsing plugin

Post by MaryRowley »

Hi,

I had the same problem.
But I done everything but somehow it doesn't work for me.
Is there any other way?
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: entry data via Smarty parsing plugin

Post by Timbalu »

peggylon wrote:...in serendipity_local_config.inc.php (which don't really work, but that's another story)

Code: Select all

$GLOBALS['i18n_filename_from'] = array(' ', '!', '%', '_', '+', ',', ';', '.', ':', '?');
$GLOBALS['i18n_filename_to'] = array('', '','','','', '','','','-'.'');
Since there is a tiny little bug in that pasted code, I'll add a corrected version here, which additionally also replaces the first arrays first empty item with a dash in the second.

Code: Select all

$GLOBALS['i18n_filename_from'] = array(' ', '!', '%', '_', '+', ',', ';', '.', ':', '?');
$GLOBALS['i18n_filename_to']   = array('-', '',  '',  '',  '',  '',  '',  '',  '-', '' );
Not sure though, that replacing the questionmark, semicolon, (etc) is actually a good idea*, since that may could hit URI appendixes...?!

(*) another (better?) option would be to use this

Code: Select all

('-', '-', '-', '-', '-', '-', '-', '-', '-', '-')
for all of them.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Post Reply