I’m trying to get a get a template to display a specific entry if none is specified in the URL. The template_group/template is “site/about”; the default entry, “About the Organization” (about-the-organization), is entry #17 in the “about” weblog.
In other words, I want http://www.example.com/site/about/ to display the same thing as http://www.example.com/site/about/about-the-organization/, instead of a list of entries.
I’ve been trying to do this by testing for {segment_3}; if it’s missing, the template would display the default entry.
<!-- Use variables to allow the code to be used for other weblogs simply by changing the values -->
{assign_variable:this_weblog="about"}
{assign_variable:default_entry="17"}
{assign_variable:this_template_group="site"}
{if segment_3} <!-- Test for segment_3; -->
{exp:weblog:entries weblog="{this_weblog}"}
{assign_variable:this_entry="{entry_id}"} <!-- if it exists (indicating the presence of a sing
single entry), assign {this_entry} the
{entry_id}'s value; -->
{/exp:weblog:entries}
{if:else}
{assign_variable:this_entry="17"} <!-- otherwise, assign {this_entry} the
{default_entry}'s value -->
{/if}
<-- Test output -->
{assign_variable:this_entry="17"}Third segment = {segment_3}; {this_entry} in {this_weblog}The resulting HTML source at http://www.example.com/site/about/:
<!-- Use variables to allow the code to be used for other weblogs simply by changing the values -->
<!-- otherwise, assign {entry_id} the
17's value -->
<--! Test output -->
Third segment = ; {entry_id} in aboutThe resulting HTML source at http://www.example.com/site/about/about-the-organization/:
<!-- Use variables to allow the code to be used for other weblogs simply by changing the values -->
<!-- Test for segment_3; -->
<!-- if it exists (indicating the presence of a sing
single entry), assign 17 the
17's value; -->
<--! Test output -->
Third segment = about-the-organization; {entry_id} in aboutAm I over-thinking this? I can’t figure out why {entry_id} isn’t getting the assigned value. (Or maybe it’s not able to retain the value outside of {exp:weblog:entries) tag pairs?)