[Solved] News mod: Detail View Settings for each category
[Solved] News mod: Detail View Settings for each category
My site has two links on the home page, one for the annual auction and one for the golf classic tournament; and I want to change these links to news articles that way the links will automatically be removed once the events are over.
If you click on the golf classic link, a new template loads up with a golf theme. I would like this to happen when a news article is added to the golf category; and the current template to load up when a news article is added to the general category. The problem is I am completely lost on how to do this.
The Detail Templates in the news module only controls how the news articles' content is formated. Not how the page is designed. If I copy and paste the golf template into the Detail Template then I get this Inception like page within a page effect.
If I go to News -> Options -> Detail View Settings I can change the template to the golf themed template, but that will change the template for all of the categories; and I only want the golf themed template to load up when an article is added to the golf category.
If you click on the golf classic link, a new template loads up with a golf theme. I would like this to happen when a news article is added to the golf category; and the current template to load up when a news article is added to the general category. The problem is I am completely lost on how to do this.
The Detail Templates in the news module only controls how the news articles' content is formated. Not how the page is designed. If I copy and paste the golf template into the Detail Template then I get this Inception like page within a page effect.
If I go to News -> Options -> Detail View Settings I can change the template to the golf themed template, but that will change the template for all of the categories; and I only want the golf themed template to load up when an article is added to the golf category.
Last edited by DoctorWho on Wed Mar 02, 2011 3:34 pm, edited 1 time in total.
CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux
Re: News mod: Detail View Settings for each category
$entry->category contains the category name of the article. You can leverage this variable and determine what to show inside the detail template. For example:
If that would make your detail template too complicated, due to too many of these 'if' statements, then you can copy your golf detail template into a GCB (WYSIWYG off) called 'golf' and your general detail template inside a GCB called general. Then in your main detail template, you can specify:
..which would call the detail template GCB with the same name as the category.
Code: Select all
{if $entry->category == 'golf'}
{* Show Golf Stuff *}
{else}
{* Show General Stuff *}
{/if}
Code: Select all
{global_content name=$entry->category}
Re: News mod: Detail View Settings for each category
Thanks wishbone for your fast reply. My news detail templates looks like this:
My site is on the basic side of things, so I only need the content from the news article to be displayed. For both the general template and the golf template.
I tried copying the general template and the golf template in to their own GCB. Then I pasted into the default news detail template; and I got the the page within a page effect again, located here.
Now the general template appears when an article is added to general category and likewise for the golf template and category. So some progress is being made here.
My test site can be found here.
Code: Select all
{eval var=$entry->content}
I tried copying the general template and the golf template in to their own GCB. Then I pasted
Code: Select all
{global_content name=$entry->category}
Now the general template appears when an article is added to general category and likewise for the golf template and category. So some progress is being made here.
My test site can be found here.
CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux
Re: News mod: Detail View Settings for each category
I think you want a fairly standard/generic/universal detail template, but you want your page template to change based on the news article category. Yes?
Re: News mod: Detail View Settings for each category
You got it.jmcgin51 wrote:I think you want a fairly standard/generic/universal detail template, but you want your page template to change based on the news article category. Yes?
CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux
Re: News mod: Detail View Settings for each category
UNTESTED:
Create 2 new Global Content Blocks, one containing an ENTIRE Golf page template, and one containing an ENTIRE generic/default template.
Now create a new Page Template. It will be empty except for wishbone's code that you'll use to determine the article category. Then simply call the correct GCB to fill in the rest of the template, based on the article category.
There is probably a more elegant way to do it, but I think this will work. If this doesn't make sense, let me know and I'll try to be more detailed.
Create 2 new Global Content Blocks, one containing an ENTIRE Golf page template, and one containing an ENTIRE generic/default template.
Now create a new Page Template. It will be empty except for wishbone's code that you'll use to determine the article category. Then simply call the correct GCB to fill in the rest of the template, based on the article category.
There is probably a more elegant way to do it, but I think this will work. If this doesn't make sense, let me know and I'll try to be more detailed.
Re: News mod: Detail View Settings for each category
Thanks jmcgin51 and whisbone for all of your help. I deeply appreciate it.
I am still stuck on getting this to work. Here's what I did:
I went to Layout » Templates and I copied my default template, then I went to Content » Global Content Blocks and I created a new GCB called general, and I pasted my default template in. Then I did the same for the golf template and created a new GCB called golf.
Now here's where things get a fuzzy. I went to ayout » Templates to create a new Page Template (called News) and I pasted
inside.
Now when I click on a news article on the home page, all I get is a blank web page.
My news detail template looks like this:
I am still stuck on getting this to work. Here's what I did:
I went to Layout » Templates and I copied my default template, then I went to Content » Global Content Blocks and I created a new GCB called general, and I pasted my default template in. Then I did the same for the golf template and created a new GCB called golf.
Now here's where things get a fuzzy. I went to ayout » Templates to create a new Page Template (called News) and I pasted
Code: Select all
{global_content name=$entry->category}
Now when I click on a news article on the home page, all I get is a blank web page.
My news detail template looks like this:
Code: Select all
{eval var=$entry->content}
CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux
Re: News mod: Detail View Settings for each category
You could do something like this:
Open your "News Detail Template" and add somewhere on top:
Now open your "Layout -> Templates -> your current Template" and do following.
On top of the template replace {process_pagedata} with:
Replace the {content} tag in your template with {$capturedcontent}
Now you can change your markup based on "News Detail Page and Category"
In the <head> part where {cms_stylesheet} is located you can change the stylesheet for your Page Template using
And for the rest of the Template markup after </__body> tag:
I hope i understood what you are trying to achieve 
Open your "News Detail Template" and add somewhere on top:
Code: Select all
{assign var="setdetail" value='1'}
On top of the template replace {process_pagedata} with:
Code: Select all
{content assign="capturedcontent"}
Now you can change your markup based on "News Detail Page and Category"
In the <head> part where {cms_stylesheet} is located you can change the stylesheet for your Page Template using
Code: Select all
{if isset($setdetail) && ($entry->category == 'golf')}
{cms_stylesheet name='name_of_stylesheet_for_layout_1'}
{else}
{cms_stylesheet name='name_of_stylesheet_for_layout_2'}
{/if}
Code: Select all
</__body>
{if isset($setdetail) && ($entry->category == 'golf')}
<div class="something">
some stuf, well your whole template version 1 beginning after </__body> and ending before <__body>
</div>
{else}
<div class="something">
some stuf, well your whole template version 2 beginning after </__body> and ending before <__body>
</div>
{/if}
<__body>
</__html>

Re: News mod: Detail View Settings for each category
Major thanks uniqu3! This is exactly what I was looking for!


CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux
Re: [Solved] News mod: Detail View Settings for each categor
Np
If markup of your templates is identical and all thats different are your stylesheets you could leave out the last part and simply create a template without attached stylesheet as you call stylesheets with name= parameter.

If markup of your templates is identical and all thats different are your stylesheets you could leave out the last part and simply create a template without attached stylesheet as you call stylesheets with name= parameter.
Re: [Solved] News mod: Detail View Settings for each categor
One last thing (I promise), I am having some issues with the page title. I would like the home page to display 'Home' and when I go to a news article the article's title would appear in the title.
I tried using {$cgsimple->get_root_alias()} but only displayed the page alias; i.e. 'Home'
So I need a way to get the entire URL, then parse through it and look the phrase 'news' in the link.
Something like this:
I tried using {$cgsimple->get_root_alias()} but only displayed the page alias; i.e. 'Home'
So I need a way to get the entire URL, then parse through it and look the phrase 'news' in the link.
Something like this:
Code: Select all
{if page url contains 'news'}
{$entry->title|cms_escape}
{else}
{title}
CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux
Re: [Solved] News mod: Detail View Settings for each categor
Wayne = Wishbone already wrote an article about this http://www.i-do-this.com/blog/29/Settin ... News-title
Re: [Solved] News mod: Detail View Settings for each categor
Excellent! Thanks again! 

CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux
Re: [Solved] News mod: Detail View Settings for each categor
Hi
I'm trying to do this too but I can't get it to work.
I've got some of it to work (using jmcgin51's suggestion) except for the part where I'm trying to get the category name for the news entry, see below.
{global_content name=$entry->category}
If i replace "$entry->category" with the actual name of a news category it works. It seems to be having a problem resolving "$entry->category" and i get the error below in the browser:
string(55) "Smarty error: unable to read resource: "globalcontent:""
Any suggestions are very welcome!!
I'm trying to do this too but I can't get it to work.
I've got some of it to work (using jmcgin51's suggestion) except for the part where I'm trying to get the category name for the news entry, see below.
{global_content name=$entry->category}
If i replace "$entry->category" with the actual name of a news category it works. It seems to be having a problem resolving "$entry->category" and i get the error below in the browser:
string(55) "Smarty error: unable to read resource: "globalcontent:""
Any suggestions are very welcome!!
Re: [Solved] News mod: Detail View Settings for each categor
You actually have a GCB with a name that matches the category name, right?