Page 1 of 1

Having startpage mimic individual entry page

Posted: Sat Aug 26, 2006 6:30 am
by pmcaleer
Hi folks,

I'm working on customizing a fresh s9y install, and am running into a bit of a problem. The site I'm working on has had daily content - only one entry per day - since its inception, and will always be this way.

With our old system, the startpage for the site was essentially a view for the last entry. The URL didn't change; it simply dipped into the archives and pulled out the last entry, comments and all.

With s9y I'm finding it difficult to duplicate this behavior. I can get the startpage to show one entry and its comments, but no matter what I do, I can't get the comment form to show (and the $COMMENTFORM variable is there without any weird 'if' block around it, in entries.tpl.)

I also need to fish out the entry's title to show it up in the page's title tag.

Essentially, I need the startpage to be less special!

Any advice? If you need further details, please ask.

Thank you!

- Paul

Re: Having startpage mimic individual entry page

Posted: Sat Aug 26, 2006 12:06 pm
by garvinhicking
Hi!

First the easier thing, to use your entry title, edit your index.tpl file. At the top add this:

Code: Select all

    {foreach from=$entries item="dategroup"}
        {foreach from=$dategroup.entries item="entry"}
        {if NOT $first_entry}
            {assign var="first_entry" value=$entry}
        {/if}
        {/foreach}
    {/foreach}
This code will put the contents of the first entry in the variable {$first_entry}, which you can later use in your <title> etc. sections, like {$first_entry.title}. You could create a custom modifier to avoice the smarty foreach-loops, but this is a tad more complicated at this point and I don't want to confuse you.

Now, as for the showing of the commentform. In your entries.tpl you need to check the {$is_single_entry} variable. This one is not set when being in the "overview". So you must put the display of the comment variable outside of any IF-Structures that only are visible when $is_single_entry is set.

In my default template it looks like:

Code: Select all

        {if $is_single_entry and not $is_preview}
            <div class="serendipity_comments serendipity_section_comments">
                <br />
                <a id="comments"></a>
                <div class="serendipity_commentsTitle">{$CONST.COMMENTS}</div>
                <div class="serendipity_center">{$CONST.DISPLAY_COMMENTS_AS}
                {if $entry.viewmode eq $CONST.VIEWMODE_LINEAR}
                    ({$CONST.COMMENTS_VIEWMODE_LINEAR} | <a href="{$entry.link_viewmode_threaded}#comments" rel="nofollow">{$CONST.COMMENTS_VIEWMODE_THREADED}</a>)
                {else}
                    (<a rel="nofollow" href="{$entry.link_viewmode_linear}#comments">{$CONST.COMMENTS_VIEWMODE_LINEAR}</a> | {$CONST.COMMENTS_VIEWMODE_THREADED})
                {/if}
                </div>
                <br />
                    {serendipity_printComments entry=$entry.id mode=$entry.viewmode}

                {if $entry.is_entry_owner}
                    {if $entry.allow_comments}
                    <div class="serendipity_center">(<a href="{$entry.link_deny_comments}">{$CONST.COMMENTS_DISABLE}</a>)</div>
                    {else}
                    <div class="serendipity_center">(<a href="{$entry.link_allow_comments}">{$CONST.COMMENTS_ENABLE}</a>)</div>
                    {/if}
                {/if}
                <a id="feedback"></a>

                {foreach from=$comments_messagestack item="message"}
                <div class="serendipity_center serendipity_msg_important">{$message}</div>
                {/foreach}

                {if $is_comment_added}

                <br />
                <div class="serendipity_center serendipity_msg_notice">{$CONST.COMMENT_ADDED}</div>

                {elseif $is_comment_moderate}

                <br />
                <div class="serendipity_center serendipity_msg_notice">{$CONST.COMMENT_ADDED}<br />{$CONST.THIS_COMMENT_NEEDS_REVIEW}</div>

                {elseif not $entry.allow_comments}

                <br />
                <div class="serendipity_center serendipity_msg_important">{$CONST.COMMENTS_CLOSED}</div>

                {else}

                <br />
                <div class="serendipity_section_commentform">
	                <div class="serendipity_commentsTitle">{$CONST.ADD_COMMENT}</div>
	                {$COMMENTFORM}
				</div>

                {/if}
            </div>
        {/if}
and it needs to be modified to this:

Code: Select all

            <div class="serendipity_comments serendipity_section_comments">
                <br />
                <a id="comments"></a>
                <div class="serendipity_commentsTitle">{$CONST.COMMENTS}</div>
                <div class="serendipity_center">{$CONST.DISPLAY_COMMENTS_AS}
                {if $entry.viewmode eq $CONST.VIEWMODE_LINEAR}
                    ({$CONST.COMMENTS_VIEWMODE_LINEAR} | <a href="{$entry.link_viewmode_threaded}#comments" rel="nofollow">{$CONST.COMMENTS_VIEWMODE_THREADED}</a>)
                {else}
                    (<a rel="nofollow" href="{$entry.link_viewmode_linear}#comments">{$CONST.COMMENTS_VIEWMODE_LINEAR}</a> | {$CONST.COMMENTS_VIEWMODE_THREADED})
                {/if}
                </div>
                <br />
                    {serendipity_printComments entry=$entry.id mode=$entry.viewmode}

                {if $entry.is_entry_owner}
                    {if $entry.allow_comments}
                    <div class="serendipity_center">(<a href="{$entry.link_deny_comments}">{$CONST.COMMENTS_DISABLE}</a>)</div>
                    {else}
                    <div class="serendipity_center">(<a href="{$entry.link_allow_comments}">{$CONST.COMMENTS_ENABLE}</a>)</div>
                    {/if}
                {/if}
                <a id="feedback"></a>

                {foreach from=$comments_messagestack item="message"}
                <div class="serendipity_center serendipity_msg_important">{$message}</div>
                {/foreach}

                {if $is_comment_added}

                <br />
                <div class="serendipity_center serendipity_msg_notice">{$CONST.COMMENT_ADDED}</div>

                {elseif $is_comment_moderate}

                <br />
                <div class="serendipity_center serendipity_msg_notice">{$CONST.COMMENT_ADDED}<br />{$CONST.THIS_COMMENT_NEEDS_REVIEW}</div>

                {elseif not $entry.allow_comments}

                <br />
                <div class="serendipity_center serendipity_msg_important">{$CONST.COMMENTS_CLOSED}</div>

                {else}

                <br />
                <div class="serendipity_section_commentform">
	                <div class="serendipity_commentsTitle">{$CONST.ADD_COMMENT}</div>
	                {$COMMENTFORM}
				</div>

                {/if}
            </div>
Depending on your s9y version, you might be able to use the $view variable to check if you are on a startpage, or on an detailed entry page, or in entry overview...

Best regards,
Garvin

Posted: Sun Aug 27, 2006 2:57 am
by pmcaleer
The title fix worked great - so thanks, Garvin.

However the comment form is still being stubborn. I tried a straight up copy and paste of your code and no go. Then I removed the tag from all of the logic - in fact I've removed the single entry logic altogether - to no avail. The $view variable is indeed "start", and if I do something explicit like this:

Code: Select all

{if $view == "start"}
     {$COMMENTFORM}
{/if}
...it still doesn't show. It does still show on any archived page.

Any other thoughts or settings I need to check out? It seems like it should be something really simple.

Thanks again,

- Paul

Posted: Sun Aug 27, 2006 12:57 pm
by garvinhicking
Hi!

Oh, I'm really sorry. I just saw that indeed the commentform only gets displayed for single entries.

You will need to create/modify your config.inc.php file in your template directory.

Enter this code:

Code: Select all

<?php
/**
 * Smarty Function: Shows a commentform
 *
 * @access public
 * @param   array       Smarty parameter input array:
 *                          id: An entryid to show the commentform for
 *                          url: an optional HTML target link for the form
 *                          comments: Optional array of containing comments
 *                          data: possible pre-submitted values to the input values
 *                          showToolbar: Toggle whether to show extended options of the comment form
 *                          moderate_comments: Toggle whether comments to this entry are allowed
 * @param   object  Smarty object
 * @return  void
 */
function showCommentForm($params, &$smarty) {
    global $serendipity;
    
    if (!isset($params['id']) || !isset($params['entry'])) {
        $smarty->trigger_error(__FUNCTION__ .": missing 'id' or 'entry' parameter");
        return;
    }

    if (empty($params['url'])) {
        $params['url'] = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?url=' . $params['entry']['commURL']
    }

    if (!isset($params['comments'])) {
        $params['comments'] = NULL;
    }
    
    if (!isset($params['data'])) {
        $params['data'] = $serendipity['POST'];
    }
    
    if (!isset($params['showToolbar'])) {
        $params['showToolbar'] = true;
    }
    
    if (!isset($params['moderate_comments'])) {
        $params['moderate_comments'] = serendipity_db_bool($params['entry']['moderate_comments']);
    }
    
    
    $comment_add_data = array(
        'comments_messagestack' => (isset($serendipity['messagestack']['comments']) ? (array)$serendipity['messagestack']['comments'] : array()),
        'is_comment_added'      => (isset($serendipity['GET']['csuccess']) && $serendipity['GET']['csuccess'] == 'true' ? true: false),
        'is_comment_moderate'   => (isset($serendipity['GET']['csuccess']) && $serendipity['GET']['csuccess'] == 'moderate' ? true: false)
    );

    $smarty->assign($comment_add_data);

    serendipity_displayCommentForm(
        $params['id'],
        $params['url'],
        $params['comments'],
        $params['data'],
        $params['showToolbar'],
        $params['moderate_comments'],
        $params['entry']
    );
    
    return true;
}

$serendipity['smarty']->register_function('showCommentForm', 'showCommentForm');
I will also commit this code as a default smarty function to serendipity 1.1.

Now you have this smarty function and you can call it inside your template like this:

Code: Select all

{showCommentForm id=$entry.id entry=$entry}
{$COMMENTFORM}
Does that work for you? My development environment is currently down because my server had a hardware failure and I was not able to get replacement yet, so I can't test this currently.

Best regards,
Garvin

Posted: Sun Aug 27, 2006 2:45 pm
by pmcaleer
It works!

Note, though, that in this block of code:

Code: Select all

  if (empty($params['url'])) { 
    $params['url'] = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?url=' . $params['entry']['commURL'] 
  } 
...there's a missing semicolon at the very end :) This was throwing me for a loop at first!

Your help is very, very much appreciated. Thank you!

- Paul

Posted: Sun Aug 27, 2006 2:54 pm
by garvinhicking
Hi!

Yes, just after posting I noticed that as well and forget to edit the code here! :-(

Great to hear it works! Have fun with serendipity!

Best regards,
Garvin