Page 1 of 1

Using {entry.id} in plugin_mediainsert.tpl

Posted: Sat Apr 02, 2011 10:17 am
by narrenfrei
Hi,
would like to use the {entry.id} in the template for mediainsert (serendipity_event_entryproperties), but in the plugin_mediainsert.tpl this smarty-tag is not known.

Is there a way to get the entry.id from the entry in which the mediainsert is used?

I need it to generate an id for a slider-div using java-script which must be unique.

Korrektur:
plugin_mediainsert.tpl ist not form the serendipity_event_entryproperties-plugin, but serendipity_event_imageselectorplus.

Re: Using {entry.id} in plugin_mediainsert.tpl

Posted: Sat Apr 02, 2011 10:30 am
by Timbalu
You have to search in the $entries array, like {$entries|print_r}.
Maybe the id could be in something like {$entries.entries.id}

Re: Using {entry.id} in plugin_mediainsert.tpl

Posted: Sat Apr 02, 2011 1:17 pm
by narrenfrei
Hi, thanks for your tip. But it doesn't work within the plugin_mediainsert.tpl
In the entries.tpl {$entry.id} works. In the template for the mediainsert I've tried some different tags:
{$entries.entries.id}
{$entries.X.entries.id}
{$entries.X.entries.Y.id}
{$entries.entries.0.id}

In the entries.tpl I got with {$entries|print_r} the following result:

Code: Select all

Array
(
    [date] => 1301484574
    [is_sticky] => 
    [entries] => Array
        (
            [0] => Array
                (
                    [id] => 25
                    [title] => XML-Bildserien
                    [timestamp] => 1301484574
                    [body] =>     
Same tag in the plugin_mediainsert.tpl results in nothing.

Garvin has written in his book, that {$entries} is only reachable in entries.tpl and entries_summary.tpl

Re: Using {entry.id} in plugin_mediainsert.tpl

Posted: Sun Apr 03, 2011 9:28 am
by Timbalu
Yes, $entries is available, since $entry is just onother name for a looping part of it.
So if you know the entries date and the array key {$entries.20110313.entries.0.id} or {$entries[20110313].entries[0].id} or similar should do to get the id num. If this is dynamic entry content there you have to find another way.

....

As I thought about it, I found plugin_mediainsert.tpl not to be in serendipity_event_entryproperties, but in serendipity_event_imageselectorplus, which is something totally different.

The plugin has its own database call which does not include the id.
You might change it to have the id included, by hacking
SELECT name, ... to

Code: Select all

SELECT id, name,
... in line 804 and 810.
Then this should be available as {$medium.id} in you template file.

Re: Using {entry.id} in plugin_mediainsert.tpl

Posted: Mon Apr 04, 2011 9:47 am
by narrenfrei
Hi, thanks for the tipp and I'm sorry for the wrong plugin name. I've copied and pasted the wrong folder-name.

Your tipp with hacking the serendipity_event_imageselectorplus.php by insert "id" to the select-funktion ads the ID of the photo to the database. But I would like to insert the ID of the blog-entry dynamically in the plugin_mediainsert.tpl to generate a ID for a <div> that contains an image-slider. The JS which generates the slider needs an unique ID for this div. Specially if there are more than 1 sliders on a page, as it is likely often on the startpage of the blog.

If there is no way to get the ID of the blog entry, I've already found another way to generate the div-ID by using {$plugin_mediainsert_media.0.path|@makeFilename} or/and {$plugin_mediainsert_media.0.name}. The blog entry id would be nice, because it is a short string and always unique - as long, as I only use one slider per blog entry.

Re: Using {entry.id} in plugin_mediainsert.tpl

Posted: Mon Apr 04, 2011 10:30 am
by garvinhicking
Hi!

Hm, the mediainsert.tpl file is rendered during the normal s9y workflow, when an entry is being displayed through frontend_display. I can't currently setup the plugin to try it on my own, but I think you should be able to get some sort of context within the TPL file.

One thing you could try is to place a {debug} in the .tpl file, this should give you an overview of all variables available inside the tpl.

If that does not reveal anything, we could try to further patch the plugin. When $this->media_insert() is called, it does not pass through the whole $eventData array. We could try to do that, and then pass this $eventData along to the smarty rendering of the .tpl file...

Regards,
Garvin

Re: Using {entry.id} in plugin_mediainsert.tpl

Posted: Mon Apr 04, 2011 10:50 am
by Timbalu
I see!
But the entry id should be available, since the plugin acts like a normal blog entry. Before and after the id is available, so it must be for your plugin_mediainsert.tpl.

Where does the jQuery thing come from? It is not in serendipity_event_imageselectorplus...
This is the place where you want the entry id.

You might be able to pass the id through by hacking the

Code: Select all

~426 	case 'frontend_display':
event hook, adding something like

Code: Select all

if (!empty($eventData['id'])) {
    $serendipity['smarty']->assign('entry_id', $eventData['id']);
}
before the

Code: Select all

~458 	return true;
Then you might be able to have the entry id in the smarty var {$entry_id}

Re: Using {entry.id} in plugin_mediainsert.tpl

Posted: Mon Apr 04, 2011 12:56 pm
by narrenfrei
I've tried Garvin's tipp with the {debug} in the .tpl file, but the ID of the blog entry is only in the single (detail) view reachable (via {entry_id}).

So I've aded

Code: Select all

if (!empty($eventData['id'])) {
    $serendipity['smarty']->assign('entry_id', $eventData['id']);
}
to the serendipity_event_imageselectorplus.php-file as Ian said. And now {entry_id} is reachable in single view and also in the list view on the startpage.

One more question:
Is it possible to save such changes in a s9y-extension in a way, that it's save from updates of the extension?

Re: Using {entry.id} in plugin_mediainsert.tpl

Posted: Mon Apr 04, 2011 1:27 pm
by garvinhicking
Hi!

Yes, this was the obfuscated thing I was talking about in the last instance. I just committed a patch to the plugin so taht it passes {$plugin_mediainsert_entry} to the tpl file. Then you can use {$plugin_mediainsert_entry.id} for the ID, but also .title etc.

HTH,
Garvin

Re: Using {entry.id} in plugin_mediainsert.tpl

Posted: Mon Apr 04, 2011 3:45 pm
by narrenfrei
Hi Garvin,
thanks for the patch. I've already downloaded it from SourceForge and copied it into my sy9-installation. Works great.

I'm using now

Code: Select all

<div id="slider_{$plugin_mediainsert_entry.id}_{$plugin_mediainsert_media.0.name|@makeFilename|@truncate:15:""}" class="nivoSlider">
in the tpl-file to generate a most unique id as possible. This allows me to use more than one slider per blog entry and also works at the blog list on startpage.

I think, Ian's tipp with the media id by adding "id" to "SELECT id,name, ..." in line 804 and 810 would also be nice. In my case it would shorten the div-id dramatically and the id of the media would also be more unique than the truncated name of the file.

Re: Using {entry.id} in plugin_mediainsert.tpl

Posted: Tue Apr 05, 2011 9:41 am
by garvinhicking
Hi!

Great to hear this. I've also committed the change to select 'id' as well now.

Regards,
Garvin

Re: Using {entry.id} in plugin_mediainsert.tpl

Posted: Tue Apr 05, 2011 2:04 pm
by narrenfrei
Hi Garvin,
I've installed your new patch to my blog and can tell, it works great.
Thanks a lot.

Re: Using {entry.id} in plugin_mediainsert.tpl

Posted: Sat Aug 06, 2011 11:45 pm
by garvinhicking
FilerRose wrote:This seems to be bit advanced for me. Can anyone send some URL's that I can follow from the beginning.
Are you serious? Your two postings here seem a bit spammy to me. If you respond to that, I'll try to help. :)

Regards,
Garvin