static pages using entries.tpl, revisited

Creating and modifying plugins.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: static pages using entries.tpl, revisited

Post by garvinhicking »

Hi!
I still would like to know why we should care actually, since I can't see a need to ask for $staticpage_pagetitle in entries.tpl at all.
Because that's the easiest way to differentiate whether a staticpage is shown or not? I think template files like kinetic do have a reason for this. Maybe Don could elaborate on it? (Or I overread it?)

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/
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: static pages using entries.tpl, revisited

Post by Don Chambers »

garvinhicking wrote:Because that's the easiest way to differentiate whether a staticpage is shown or not? I think template files like kinetic do have a reason for this. Maybe Don could elaborate on it? (Or I overread it?)
This is NOT unique to Kinetic. I addressed this a few posts earlier with this:
An option exists within static pages (and contact forms) to render the output to look like an entry ({if $staticpage_articleformat}), which seems to imply ("looks like output generated by entries.tpl"). This logic is processed solely within the static pages, not in entries.tpl.
In most templates, entries have a typical structure that usually includes the class serendipity_Entry_Date. plugin_staticpage.tpl, also sets this class *IF* a static page has been defined to look like an entry (from bulletproof):

Code: Select all

{if $staticpage_articleformat}
    <div id="staticpage_{$staticpage_pagetitle|@makeFilename}" class="serendipity_Entry_Date serendipity_staticpage">
    <h3 class="serendipity_date">{$staticpage_articleformattitle|@escape}</h3>
{/if}
There is no longer a way within entries.tpl to detect a static page, so no way to avoid html which may be duplicated in the static page tpls. In most templates, if not ALL templates other than 2k11 (which does not use the class serendipity_Entry_Date), static pages have a serendipity_Entry_Date container containing static page output followed by an additional serendipity_Entry_Date container rendered by entries.tpl. The second container is typically empty because entries.tpl had nothing further to contribute to the page.

Obviously, a very long time ago, other people realized that static page output could, and should, be different from that in entries.tpl. Why else would I have found notes within code saying exactly that? And why would we have options in plugins to "format as an entry", yet have no way to avoid that formatting if we cannot detect a static page within entries.tpl?

Either detecting static pages needs to be restored within entries.tpl, or static pages, contact forms, and other plugins which do not use entries.tpl, should skip it completely. My suggestion within content.tpl is not foolproof as a few plugins do require entries.tpl for html structure, unless they are modified so as not to need entries.tpl either.
=Don=
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: static pages using entries.tpl, revisited

Post by garvinhicking »

Hi Don!

I patched serendipity_event_staticpage to create a new variable $smarty.env.staticpage_pagetitle.

Within index.tpl and content.tpl (like you said) {$staticpage_pagetitle} is available. In entries.tpl, it is not. Reason is, it is created by this line in entries.tpl:

Code: Select all

{serendipity_hookPlugin hook="entries_header" addData="$entry_id"}
However, local variables which the plugin assigns, will not be accessible within entries.tpl at this point. The only way I could find with Smarty3 is to access this global $_ENV/$smarty.env variable and make the plugin assign that variable.

I suggest to patch template's entries.tpl files to now not only use:

Code: Select all

{if $staticpage_pagetitle != ''}
but change it to:

Code: Select all

{if $staticpage_pagetitle != '' or $smarty.env.staticpage_pagetitle != ''}
This way, a template should work with both older and the recent staticpage plugins.

I committed this _ENV change to all plugins that assigned this staticpage_pagetitle...

Opinions?

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/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: static pages using entries.tpl, revisited

Post by Timbalu »

garvinhicking wrote:I committed this _ENV change to all plugins that assigned this staticpage_pagetitle...
Opinions?
For me that even more shows that you "bugfix" an "issue" for what entries.tpl is not designed for...
Don Chambers wrote:... no way to avoid html which may be duplicated in the static page tpls
This confuses me more and more. (*) In entries.tpl you have the hooks and the blog $entries loop inbetween, which is not processed in case of a staticpage. So where exactly is something duplicated in case of a staticpage? Please give a working example at least, which shows the need!

I still do not see any need to ask for {if $staticpage_pagetitle != ''} in entries.tpl, outside the blog entries {foreach from=$entries item="dategroup"} loop. For me such an approach looks weird, since you either have staticpages (using their own tpl), faked staticpages like contactform (using its own tpl) or blog entries (processed by loop). I cannot understand the argue with 'serendipity_entryDate' etc being any relevant to the entries.tpl file.
Garvins fix, to propagate a global $smarty.env.staticpage_pagetitle (and the others) so that it can be used in entries.tpl, now populates a global var for us all for what reason and fixing which example?

(Even an undefined {$CONST.FOO} does not echo FOO any more with Smarty3, which IMO is the right behaviour.)

(*) The only markup in bulletproof/entries.tpl being sent to browser in case of staticpages is the empty <div class='serendipity_pageFooter' style="text-align: center"> ... </div>, which could be enclosed with a {if $footer_info or $footer_prev_page or $footer_next_page} ... {/if} or {if $footer_totalPages > 1} to avoid it.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: static pages using entries.tpl, revisited

Post by Don Chambers »

Thanks Garvin... And Ian is correct - Bulletproof creates serendipity_Entry_Date after the first foreach loop:

Code: Select all

{foreach from=$entries item="dategroup"}
    <div class="hentry serendipity_Entry_Date{if $dategroup.is_sticky} serendipity_Sticky_Entry{/if}">
I need to emit something from entries.tpl, before this first loop, but only for pages that have entries, which typically means not static pages.

So it occurs to me, instead of using {if $staticpage_pagetitle != ''} to determine that it is not a static page, couldn't I use {if $entries or not $plugin_clean_page} for the same purpose? This seems to work in my VERY quick test. Any thoughts?

And for the record - I am merely trying to recover template functionality that existed before the upgrade to smarty3. I built features into templates that worked prior to the smarty3 upgrade, and I think it is logical for me to try to preserve that functionality in the latest - and hopefully future - s9y release.
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: static pages using entries.tpl, revisited

Post by Timbalu »

Don Chambers wrote:I need to emit something from entries.tpl, before this first loop, but only for pages that have entries, which typically means not static pages.
Yes, I can imagine that..., but cannot test without an example which isn't completely theoretical.
For a long time I favoured to better ask for something which could really happen true, since you want it to happen for entries only, like

Code: Select all

{if is_array($entries) && !empty($entries)}
    // apply some 'heading' markup before entries loop, 
    // but do not stop processing fall-through to entries.tpl or the loop itself
{/if}
or move that part to content.tpl where the negation if ! staticpage is accessible.
For me, the urgent need for keeping this stick to entries.tpl is still incomprehensible.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: static pages using entries.tpl, revisited

Post by garvinhicking »

Hi!

The reason is simply that the plugins use a hook that is in entries.tpl. So we need to be able, in entries.tpl, to check if a plugin has taken over control.

If you only check for $entries and decide that it's a staticpage if $entries doesn't exist, you would also emit staticpage layout when no entries are to be displayed (maybe even because some plugins modified it).

The staticpage plugin is called through entries.tpl, so it will always be required - at least that's how I read the code?! So we can't simply "get rid" of entries.tpl, without breaking every existing template my removing the hook there.

So I actually do think it's worthwhile to make entries.tpl to be able to check for staticpage template variables. With Smarty2 this was no problem because the variables became available inside the same file, but Smarty3 doesn't work like that any more.

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/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: static pages using entries.tpl, revisited

Post by Timbalu »

That is not the point, IMHO.
As far as I understand this whole thing, Don does not want to have something for staticpages. He wants to have some heading for entries solely. To apply something to staticpages does not make any sence in entries.tpl. For this you can use the other staticpage or fake staticpage template files.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: static pages using entries.tpl, revisited

Post by Don Chambers »

My entries.tpl file is nearly 400 lines long, so rather than show the entire thing here, let me summarize it this way:

Code: Select all

{serendipity_hookPlugin hook="entries_header" addData="$entry_id"} {* emit static page *}
{if $entries or not $plugin_clean_page} {* proceed only for entry pages ?? *}
    <script type="text/javascript">{* script I only want displayed on an entry page *}
    ..... do stuff ....
    </script>
    <div class="div_outside_foreach_loops">{* open this div before first foreach instead of after *}
        <h3>Some heading options here</h3>
        {foreach from=$entries item="dategroup" name="dategroup_loop"}
             {* this is where entry_date div is usually opened
            {foreach from=$dategroup.entries item="entry" name="entry_loop"}
                 .... the usual entry stuff here...
            {/foreach}{* entry *}
        {/foreach}{* dategroup *}
    </div>{* div outside of foreach loops *}
{/if}{* entry pages only *}
Does this help at all? Ian is correct in that I am not trying to add something to entries.tpl for static pages, I am wanting static pages to NOT emit something that I have to include in entries.tpl.

Is there any reason we cannot have a different hook, and/or tpl specific to static pages, much like we have several different entries tpls? (ie, entries_summary.tpl, entries_archives.tpl...)
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: static pages using entries.tpl, revisited

Post by Timbalu »

Yes either this way with some matching vars for the $entries array (like advised - or your example) or as easy as this in content.tpl, which I have proposed to use in this thread more than once... eg.
old content.tpl

Code: Select all

...
{/if}

{$ENTRIES}
{$ARCHIVES}
<!-- CONTENT END -->
change to

Code: Select all

...
{/if}

{if $staticpage_pagetitle == '' && $view != 'plugin'} {* proceed only for entry pages *}
    <script type="text/javascript">
    ..... do stuff ....
    </script>
    <div class="div_outside_foreach_loops">
        <h3>Some heading options here</h3>
{/if}

{$ENTRIES}

{if $staticpage_pagetitle == '' && $view != 'plugin'}
    </div>
{/if}

{$ARCHIVES}
<!-- CONTENT END -->
Here you also have the option to finetune this even more with the $view = 'start|entry|plugin' var (which also is available in entries.tpl).
Regards,
Ian

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