Reputation: 457
I am using cakePHP 2.4.4. I have some common HTML/PHP code which has to be displayed multiple times like:
if(condition1){
//show html
}else if(condition2 && condition3){
//show html
}
Like this there are more than 10 condition. I don't want to repeat the same HTML. I tried to include the file. It works for path like include ("D:/common/common.php"). But I want it to be within project folder. I put it in element but I can't load it multiple times. And if I put it in view/myview/ then I cannot give proper path. What is the solution?
Upvotes: 1
Views: 1229
Reputation: 8618
I'd suggest you to create different .ctp files as elements.
For example, element_one.ctp for condition 1, 2, 3. element_two.ctp for condition 4, 5, 6.. etc.
View/Element should have element_one.ctp and element_two.ctp.
And then, in your main view page, mention the following:
if (condition1 || condition 2 || condition 3) {
echo $this->element("element_one");
} else if (condition 4 || condition 5 || condition 6) {
echo $this->element("element_two");
}
Upvotes: 2