Page 1 of 1

How do I determine startpage or frontpage?

Posted: Sat Nov 18, 2006 8:50 pm
by carl_galloway
I can't remember where this was last discussed, and my search has been without success so please forgive me for dredging up something that is possibly right in front of my eyes.

A new template I'm working on uses a different startpage (similar to hemingway) and I need to determine if a user has clicked the 'homepage' link or the 'All categories' link.

The difference is that homepage is just the base URL, whereas the all categories link adds ?frontpage to the url. I've tried using {$smarty.get} but printing the result only produces the word 'array' for both instances, so obviously this isn't the right approach. Can anyone suggest anything else? Should I be adding something to config.inc.php

Carl

Re: How do I determine startpage or frontpage?

Posted: Sat Nov 18, 2006 9:39 pm
by garvinhicking
Hi!

Maybe {$smarty.get.frontpage} does the trick?

(Yeah, I'm terribly short on time and sick once again, so I hope my bare words make some sense)

HTH,
Garvin

Posted: Sat Nov 18, 2006 9:43 pm
by carl_galloway
Is it the flu again? Get well soon, drink lots of water...

Posted: Sat Nov 18, 2006 10:12 pm
by carl_galloway
nope, that didn't work either. I assume that ?frontpage must be equal to true, but how do I test this. I've tried {if $smarty.get.frontpage} and I've also tried {if $smarty.get.frontpage == true} and neither of them seem to do anything, which suggest I'm wrong about it being equal to true.

Posted: Sat Nov 18, 2006 10:34 pm
by stm999999999
in my individual template

in index.tpl

Code: Select all

{if $startpage}
helps to find the static startpage

and in entries.tpl I have

Code: Select all

{if ($view == 'archives') || ($view == 'frontpage')}

{/if}


{if ($view == 'categories')}

{/if}

{if ($view == 'entry')}

{/if}

Posted: Sun Nov 19, 2006 6:45 am
by carl_galloway
STM999999999, sorry that didn't work either.

Let me rephrase my problem. I've got some smarty that checks to see if the user is on the startpage, and when they are, they are redirected to a new .tpl file called entries_startpage.tpl, and on this page the user only sees the first entry body in full, all other entries only show the entry title.
This is different from the normal entries.tpl which shows the bodies of all entries.

What I want to do is provide a browse function in the template so if the user clicks the 'all categories' link in the categories plugin, or the browse all entries link that I will provide, I want the user to be directed to entries.tpl instead of entries.startpage.tpl.

It should be possible to do this since the URL of the homepage and the all categories page are different, because of the ?frontpage. I've tried using every combination of {$smarty.get} and nothing seems to let me check to see if ?frontpage is part of the url or not. I NEED to know if ?frontpage is part of the url because both links (homepage or ?frontpage) activate the $view == start

I guess I could edit index.php, but this would only work on my local installation, and I plan to make this template available for download so all users of Serendipity would need to be able to use my new template without having to edit any of the core files.

Posted: Sun Nov 19, 2006 3:34 pm
by mgroeninger
You could do some like this in config.inc.php:

Code: Select all

if(isset($_POST['frontpage'])) $serendipity['smarty']->assign_by_ref('frontpage',true); 
I think that should work (but I can't test it at the moment...) Unfortunately, I'm not sure how to do it nicely in serendipity...

Posted: Sun Nov 19, 2006 3:38 pm
by garvinhicking
Hi!

Try this in your template:

Code: Select all

<pre>{$smarty.get|@print_r}</pre>
this should give you a verbose array display of how the variable looks like. You might need to set $serendipity['smarty']->security=false in your templates config.inc.php to use the "print_r" modifier.

Then check how the output is using different URLs?

HTH,
Garvin

Posted: Sun Nov 19, 2006 4:33 pm
by carl_galloway
Oh thats interesting!

The basic homepage displays this;

Code: Select all

Array
(
    [serendipity] => Array
        (
            [action] => 
            [adminAction] => 
            [subpage] => /serendipity0.91/
            [page] => 1
        )

)
1
the all categories link produces this

Code: Select all

Array
(
    [frontpage] => 
    [serendipity] => Array
        (
            [action] => 
            [adminAction] => 
            [subpage] => /serendipity0.91/index.php?frontpage
            [page] => 1
        )

)
1
BTW, ignore the 'serendipity0.91' part of the subpage url, I am actually running v1.1 beta5.

So it looks like the ?frontpage part of the url does get recognised by Serendipity and the url is put into the [subpage] part of the array, and also a new variable [frontpage] is added, but why is it empty? Is this a bug in s9y, or is this intentional.

Assuming everything is working as it should, I guess I need to figure out some way of checking to see if {$serendipity_subpage} includes the text ?frontpage within the string. Oh man, this is beyond my smarty knowledge, any ideas?

Edit: I've tried accessing {$serendipity_subpage} in index.tpl and nothing happens.

Posted: Sun Nov 19, 2006 6:36 pm
by garvinhicking
Hi!

How about:

Code: Select all

{if isset($smarty.get.frontpage)}
...
{/if}
?

Best regards,
Garvin

Posted: Sun Nov 19, 2006 6:58 pm
by carl_galloway
Garvin you rock my world!!! Works perfectly, thanks