entry properties & preview_iframe.tpl

Skinning and designing Serendipity (CSS, HTML, Smarty)
User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

entry properties & preview_iframe.tpl

Post by Don Chambers » Fri Feb 05, 2016 11:35 pm

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?

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: entry properties & preview_iframe.tpl

Post by Timbalu » Sun Feb 07, 2016 4:52 pm

Since that is a complicated issue, I'll leave that to Garvin! :!: :)
Since it may touch historical reasons...
Regards,
Ian

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

User avatar
garvinhicking
Core Developer
Posts: 30014
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: entry properties & preview_iframe.tpl

Post by garvinhicking » Wed Feb 10, 2016 2:35 pm

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
# 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/

User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Re: entry properties & preview_iframe.tpl

Post by Don Chambers » Thu Feb 11, 2016 5:57 pm

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}

User avatar
garvinhicking
Core Developer
Posts: 30014
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: entry properties & preview_iframe.tpl

Post by garvinhicking » Fri Feb 12, 2016 4:22 pm

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
# 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/

User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Re: entry properties & preview_iframe.tpl

Post by Don Chambers » Fri Feb 12, 2016 5:34 pm

Done. Thanks!

User avatar
garvinhicking
Core Developer
Posts: 30014
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: entry properties & preview_iframe.tpl

Post by garvinhicking » Tue Mar 08, 2016 4:27 pm

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>
# 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/

User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Re: entry properties & preview_iframe.tpl

Post by Don Chambers » Wed Mar 16, 2016 6:37 am

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}

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: entry properties & preview_iframe.tpl

Post by Timbalu » Wed Mar 16, 2016 12:36 pm

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}
Regards,
Ian

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

User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Re: entry properties & preview_iframe.tpl

Post by Don Chambers » Wed Mar 16, 2016 5:57 pm

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...

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: entry properties & preview_iframe.tpl

Post by Timbalu » Wed Mar 16, 2016 6:43 pm

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.
Regards,
Ian

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

User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Re: entry properties & preview_iframe.tpl

Post by Don Chambers » Wed Mar 16, 2016 7:13 pm

Assuming it does work, what is the advantage?

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: entry properties & preview_iframe.tpl

Post by Timbalu » Wed Mar 16, 2016 7:22 pm

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,
Regards,
Ian

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

User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Re: entry properties & preview_iframe.tpl

Post by Don Chambers » Wed Mar 16, 2016 7:53 pm

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!!

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: entry properties & preview_iframe.tpl

Post by Timbalu » Wed Mar 16, 2016 7:59 pm

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?
Regards,
Ian

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

Post Reply