Two Custom Templates on same page...

Permalink
On the home page of a site I'm working on I have two news lists from two separate news pages elsewhere on my site.

I need to use separate templates for both, but when it do, the two page lists keep overriding CSS styles from each other. How can I have it so both page lists are completely separate? Also, I have edited the View.php files to be slightly different, but they are also overriding.

Is there are way to rename the view.css file for each template?

Cyberdave
 
Mnkras replied on at Permalink Reply
Mnkras
you need to change the view, and the css so they don't interfere
Cyberdave replied on at Permalink Reply
Cyberdave
I'm sorry, I'm not sure what you mean...

Is there a way to rename the view.css file in each template?
jbx replied on at Permalink Reply
jbx
Hi Dave,

the easiest way, would be to wrap each view.php in a div with a specific id - for example, in your first view.php you could have <div id="newslist1"> and in your second, <div id="newslist2">. And then, just using the one view.css, you can define rules for each, by referencing the id's - eg. #newsitem1 p { color: black; } and #newsitem2 p { color: blue; }.

Make sense?

Oh, and when I say "each view.php" obviously you only have one file called view.php, but in your templates/ folder, you can add files called newslist1.php and newslist2.php and then apply the relevant one by selecting the template on your block.

Jon
Cyberdave replied on at Permalink Reply
Cyberdave
For the view.css files I have made the names of each element different by changing the class names: eg. .newsflash is now .newsflash1
.newsflashcontain is now .newsflashcontain1 etc. I have also changed the class names in the view.php file as well. This works to prevent CSS overriding.

However, the view.php files are still overriding. I have added an AddThis section to the end of one news list. I don't want on the other news list. Not sure how I can make the view.php files independent of each other. I have tried wrapping them with different div id's (below) but it doesn't seem to work. When I wrap them in a different id, do I need to change the name of the file from view.php to someting else to make it work?

<div id="news1">
<?php     
defined('C5_EXECUTE') or die(_("Access Denied."));
    $html = Loader::helper('html');
    $uh = Loader::helper('concrete/urls');
    $bt = BlockType::getByHandle('news_list');
    global $c;
jbx replied on at Permalink Reply
jbx
As I said, you have to render different templates. You're using one block called news_list correct? Inside the block folder, you have a view.php file which is your default template. To use a different template, you need to create a second file and place it inside a templates folder (/blocks/news_list/templates/myTemplate.php). If you're including your block using code, and not by clicking "add block" in the CMS as your code snippet above appears to imply, then you need to add the line
$bt->render('myTemplate');
in order to use the correct template.

Jon
Cyberdave replied on at Permalink Reply
Cyberdave
I'm adding the block by just clicking Add Block in the CMS. The Block which I have various templates for is called News_List. I have 4 different templates. Only two of them ever appear together on the same page. I am choosing the different templates within the CMS. I'm still not sure what you are explaining though... sorry
jbx replied on at Permalink Reply
jbx
Well, it kinda sounds like you're doing everything correct... You don't happen to have a live URL I can see do you??

If not, can you just list exactly what files you have inside /blocks/news_list/templates/ please??

Jon
Cyberdave replied on at Permalink Reply
Cyberdave
Hi Jon, I've just sent you a PM.
Cyberdave replied on at Permalink Reply
Cyberdave
I have tried having each template as just a PHP file inside the templates folder. eg. news.php, small_news.php etc and having only one view.css... The view.php files are still interfering with each other. Can anybody help me on this? I have spent the last two evenings trying to figure it out... Please.
cursal replied on at Permalink Reply
cursal
Did this ever get worked out?
I am having same issues..