Hello, I really need a help, I have a view that has an element, but this view is used for all the pages of my site, but in some pages I do not need the element, but I need to use the view, can you "block" that element of those pages?
Hello, I really need a help, I have a view that has an element, but this view is used for all the pages of my site, but in some pages I do not need the element, but I need to use the view, can you "block" that element of those pages?
Just pick up the element code and put it in the /views/elements
Do not forget to save with the .ctp extension
To use it, use in your view: $this->element('nome_do_elemento')
. Use it only in the views you want;)
You can get the name of the current page in $this->name
(in the view);
Then you create an array with every page where the element will not appear and checks before calling the element in your view in>;
// Array com os nomes das páginas que o elemento não deve aparecer
$paginas = array("page1", "page2", "page2", "page3");
// Verifica se a página atual está entre as e não deve aparecer
if (!in_array($this->params['action'], $paginas))){
// imprime o elemento
echo $this->element('nome_do_elemento');
}
It has already been resolved, I duplicated the layout that controller
of view
used, then instantiated the element in layout that view
used, in view
. Then I changed the pages I did not want to use the layout for the duplicate layout (without element
), and now it's running clean.