Page 1 of 1
entry data via Smarty parsing plugin
Posted: Wed Feb 20, 2013 2:23 pm
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
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!
Re: entry data via Smarty parsing plugin
Posted: Wed Feb 20, 2013 3:40 pm
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
Re: entry data via Smarty parsing plugin
Posted: Wed Feb 20, 2013 4:07 pm
by peggylon
Thanks Garvin, that's the way to go. At least for most of the current entry's data.
outputs the desired title.
What the $smartymarkup_eventData array does not contain and what I'm after is the current entry's url, though.
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
Re: Smarty parsing plugin
Posted: Wed Feb 20, 2013 4:25 pm
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
Re: entry data via Smarty parsing plugin
Posted: Wed Feb 20, 2013 4:43 pm
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
Re: entry data via Smarty parsing plugin
Posted: Wed Feb 20, 2013 4:56 pm
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!
Re: entry data via Smarty parsing plugin
Posted: Thu Mar 07, 2013 12:39 pm
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?
Re: entry data via Smarty parsing plugin
Posted: Sat Feb 20, 2016 2:13 pm
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.