Page 1 of 1
Permalink in variable
Posted: Fri Feb 01, 2008 10:58 pm
by Cel
Hi,
I need to construct the permalink of an entry with smarty or php. I would like to use it to dynamically generate buttons for social bookmarking of an entry. As far as I can tell there is not a smarty variable holding the permalink. What would be the simplest way to get it ?
Regards,
Cel
Re: Permalink in variable
Posted: Sat Feb 02, 2008 12:10 pm
by garvinhicking
Hi!
The permalink of an entry is stored in {$entry.rdf_ident}!
HTH,
Garvin
Posted: Sat Feb 02, 2008 7:23 pm
by Cel
Hi Garvin,
I was hoping it would be something simple like this. However, this variable seems to be not available in the entry itself (i.e. the body text).
The documentation says it is just available in entries.tpl. I would like to decide on a case by case basis whether to include the social bookmarking buttons or not. (for some of my entries they don't make sense).
I guess I need a variable that is available in *.tpl ? Or alternatively, can I define a variable in the entry body text and then use that variable in entries.tpl to decide if it should display the buttons or not ?
Regards,
Cel
Posted: Sat Feb 02, 2008 7:58 pm
by garvinhicking
Hi!
I was hoping it would be something simple like this. However, this variable seems to be not available in the entry itself (i.e. the body text).
What do you mean? The variable is available inside the entries.tpl template. Where exactly do you want it?
Are you talking about the smarty markup plugin?
The variable is only available in the context of an entry, it doesn't make any sense in index.tpl (even though you can address it by looping through $entries)
Regards,
Garvin
Posted: Sun Feb 03, 2008 3:35 pm
by Cel
Hi,
What I mean is that I need the variable for code that I want to put in the entry body text. (Which then would be parsed by smarty markup plugin).
Regards,
Cel
Posted: Sun Feb 03, 2008 4:02 pm
by garvinhicking
Hi!
Okay, that is more complex then.
Are you really sure you need to do that with smarty markup WITHIN an entry, instead of editing the entries.tpl template and using custom entryproperties to indicate if you need the output?
The reason is, it gets hard to do that with smartymarkup. When the plugin is executed, it did not get any variables of its own entry. For that I patched the plugin in version 1.7 so that {$smartymarkup_eventData} gets passed to the smarty template of your entry body. So you need to fetch that plugin version from CVS / Spartacus.
So now you can acces {$smartymarkup_eventData.id} for the entryid.
Howver, rdf_ident will not be available then. You will need to build that with your own custom smarty function.
To do so, you need to edit your template's config.inc.php file and register yuor own smarty modifier:
Code: Select all
function serendipity_smarty_archiveURL($id, $title, $timestamp) {
return serendipity_archiveURL($id, $title, 'baseURL', true, array('timestamp' => $timestamp));
}
$serendipity['smarty']->register_modifier('serendipity_smarty_archiveURL', 'serendipity_smarty_archiveURL');
Once you have done so, you can use this smarty markup in your entry:
Code: Select all
My Full Permalink is: {$smartymarkup_eventData.id|serendipity_smarty_archiveURL:$smartymarkup_eventData.title:$smartymarkup_eventData.timestamp}
Now you can pass that variable arround, maybe you even need to use {capture} or {assign} around it, depending on what you need the permalink for.
Regards,
Garvin
Posted: Sun Feb 03, 2008 4:40 pm
by Cel
Hi,
[quote]Are you really sure you need to do that with smarty markup WITHIN an entry, instead of editing the entries.tpl template and using custom entryproperties to indicate if you need the output?[/quote]
This is the alternative method I was looking for. From the documentation of custom entryproperties It was not clear to me that I could use that for any purpose.
I will try this route first. Thanks.
Regards,
Cel