Page 1 of 2

entry properties & preview_iframe.tpl

Posted: Fri Feb 05, 2016 11:35 pm
by Don Chambers
Don't you just love when a subject includes "preview_iframe.tpl"?? :twisted:

So I am just about finished with another theme that, like Clean Blog, uses extended properties to contain images for each entry. In entries.tpl, displaying that image in my current (unreleased) theme works like this:

Code: Select all

<img src="{$entry.properties.timeline_image}" alt=""/>
From entries.tpl, I see {$entries.properties|print_r} like this:
Array ( [ep_access] => public [ep_cache_body] =>Etiam volutpat consectetur purus vel consectetur. Cum sociis.....

[ep_cache_extended] =>Donec iaculis lorem vel sapien lobortis placerat. Ut tempus odio vitae nulla cursus volutpat.

[timeline_image] =>/uploads/myfile-12b.jpg

[freetag_tags] => Array ( [0] => aquamarine [1] => chartreuse [2] => yellow )

[freetag_tagList] => aquamarine,chartreuse,yellow )
But in preview_iframe.tpl, {$entry.properties|print_r} gives me only this:
Array ( [ep_access] => public [ep_entrypassword] => ) 1
So, I have no extended property field containing my image(s) in the preview. Is there any way to get these custom defined extended properties into the preview?

Re: entry properties & preview_iframe.tpl

Posted: Sun Feb 07, 2016 4:52 pm
by Timbalu
Since that is a complicated issue, I'll leave that to Garvin! :!: :)
Since it may touch historical reasons...

Re: entry properties & preview_iframe.tpl

Posted: Wed Feb 10, 2016 2:35 pm
by garvinhicking
Phew. Hard to say. It could be that in the preview we don't actually store the properties yet; for that the entry might need to be saved first; did you try if that would work?

Other than that, you might need to fetch the entryproperties from the POST array. Not sure right now what that variable is, possibly $smarty.POST or something like it. Maybe even put a {debug} in your .tpl file to see the smarty debugging console, and check if any variable there has your content...?

Regards,
Garvin

Re: entry properties & preview_iframe.tpl

Posted: Thu Feb 11, 2016 5:57 pm
by Don Chambers
garvinhicking wrote:Phew. Hard to say. It could be that in the preview we don't actually store the properties yet; for that the entry might need to be saved first; did you try if that would work?

Yes, I have tried that. Does not work. Properties still not available on preview.
garvinhicking wrote:Maybe even put a {debug} in your .tpl file to see the smarty debugging console, and check if any variable there has your content...?
Nope. Nothing in there for extended properties using {debug}

Re: entry properties & preview_iframe.tpl

Posted: Fri Feb 12, 2016 4:22 pm
by garvinhicking
OK, that shouldn't be. Could you open a github issue, something like "assign variable for entryproperties for preview". I'll try to take care of this when I got a few minutes to spare...

Regards,
Garvin

Re: entry properties & preview_iframe.tpl

Posted: Fri Feb 12, 2016 5:34 pm
by Don Chambers
Done. Thanks!

Re: entry properties & preview_iframe.tpl

Posted: Tue Mar 08, 2016 4:27 pm
by garvinhicking
Just to repeat what I just added to the issue:

You can access the props via:

Code: Select all

PROPS: <pre>{$smarty.session.save_entry_POST.properties|print_r}</pre>

Re: entry properties & preview_iframe.tpl

Posted: Wed Mar 16, 2016 6:37 am
by Don Chambers
Thanks for the advice Garvin. Allow me to share my findings.

I thought a theme would need to modify preview_iframe.tpl to see custom entry properties during an entry preview. This assumption is incorrect.

preview_iframe.tpl prints the entire entry preview via {$preview}. $preview is the entire entry content generated by entries.tpl.

Using my original question in this thread as an example, entries.tpl might display an image contained in an entry property field like this: <img src="{$entry.properties.my_image}" alt="" />.

However, as noted in my original post, $entry.properties is not available during a preview. With a little help from Garvin's post above, entry properties ARE available to a preview via something like this:
$smarty.session.save_entry_POST.properties.my_image.

So, we have two issues:
1) We need our entry property image in the context of the entire entry, and not just injected into the preview and
2) $entry.properties isn't available in preview, but $smarty.session.save_entry_POST.properties IS available in previews....

So, my solution (unless someone has a better idea) is to use a conditional test for preview directly within entries.tpl rather than modify preview_iframe.tpl to show an image contained in an entry property:

Code: Select all

{if $is_preview}
    {if $smarty.session.save_entry_POST.properties.my_image}
        <img class="serendipity_image_left" src="{$smarty.session.save_entry_POST.properties.my_image}" alt="" />
    {/if}           
{else}
    {if $entry.properties.my_image}
        <img class="serendipity_image_left" src="{$entry.properties.my_image}" alt="" />
    {/if}
{/if}

Re: entry properties & preview_iframe.tpl

Posted: Wed Mar 16, 2016 12:36 pm
by Timbalu
I am not trying to answer your question .... but ...

I always understood entries_preview.tpl to NOT be a full extended copy of the normal entries workflow, than just as a helper function to show the essentials. So this lacks some of the extended (properties), while being build independently.

Now, did you try to assign this to that? eg (untested, though you might guess my try with the subarray)

Code: Select all

{assign var="entry['properties']" value=$smarty.session.save_entry_POST.properties}

Re: entry properties & preview_iframe.tpl

Posted: Wed Mar 16, 2016 5:57 pm
by Don Chambers
Timbalu wrote:Now, did you try to assign this to that? eg (untested, though you might guess my try with the subarray)

Code: Select all

{assign var="entry['properties']" value=$smarty.session.save_entry_POST.properties}
I played with this for a few minutes, but didn't get it to work...

Re: entry properties & preview_iframe.tpl

Posted: Wed Mar 16, 2016 6:43 pm
by Timbalu
Hmm, there must somehow be a way to include that ['properties'] subarray into the $entries array during compilation...

inside entries

Code: Select all

    {assign var="entry" value=$entry scope="parent"}
    {append var='entry' value=$smarty.session.save_entry_POST.properties index='properties'}
<pre>Test: {$entry|print_r}</pre>
should do.

Re: entry properties & preview_iframe.tpl

Posted: Wed Mar 16, 2016 7:13 pm
by Don Chambers
Assuming it does work, what is the advantage?

Re: entry properties & preview_iframe.tpl

Posted: Wed Mar 16, 2016 7:22 pm
by Timbalu
Don Chambers wrote:Assuming it does work, what is the advantage?
$entry.properties is available. Isn't that what you wanted?
That could easily be ported to preview or already be what you wanted to have,

Re: entry properties & preview_iframe.tpl

Posted: Wed Mar 16, 2016 7:53 pm
by Don Chambers
This piece isn't necessary, but I suspect that is a leftover from your test:

Code: Select all

{assign var="entry_title" value=$entry.title scope="global"}
So, YES! Instead of two substantially similar code blocks using two different arrays, can simply do this:

Code: Select all

{if $is_preview}
    {assign var="entry" value=$entry scope="parent"}
    {append var='entry' value=$smarty.session.save_entry_POST.properties index='properties'}
{/if}
{if $entry.properties.my_image}
    <img class="serendipity_image_left" src="{$entry.properties.my_image}" alt="" />
{/if}
Nice job!!

Re: entry properties & preview_iframe.tpl

Posted: Wed Mar 16, 2016 7:59 pm
by Timbalu
Don Chambers wrote:This piece isn't necessary, but I suspect that is a leftover from your test:
Yeah! It was there a while without me noticing... I already had removed that some minutes ago!
Don Chambers wrote:So, YES! Instead of two...
Fine. Is that placed in entries.tpl only?