Element cakephp

Asked

Viewed 277 times

0

Hello, I actually need a help, I have a view that has an element, only that this view is used for all pages of my site, only, on some pages I do not need the element,but I need to use the view, it is possible to "block" this element of these pages?

3 answers

1


Just take the element code and put it in the folder /views/elements

Don’t forget to save with the extension .ctp

To use it, use in your view: $this->element('nome_do_elemento'). Use it only in the views you want ;)

  • not that he wants to know, he wants to know how to show the view on some pages and others not

  • What you said doesn’t make sense. It can only have Elents in separate views or files. If he has it in separate files he obviously knows how to use it in the view he wants, then he has it in his own view. My explanation answers.

  • look at this part of the question "only, on some pages I don’t need the element,but I need to use the view"

  • Because it has an element embedded in the view. If it separates this Elements into files as mentioned above you can use it in the views you want. Read on before commenting: http://book.cakephp.org/2.0/pt/views.html

  • I know the documentation from cover to cover, what I’m saying is that apparently it doesn’t meet his need, by what I understand of the question, it uses the view on every page, but in the view there is an element that doesn’t need to be on every page, I will post my answer on what I understood of the question.

  • Then post your answer and let it rewrite. The option to negative the answer is at your disposal. I close here.

  • I have a view that encompasses 80 pages on my site, only recently, includes 5 more pages with this view, but I don’t want to use the element that is in the view, only the view.

  • Then my solution is right for you :)

Show 3 more comments

0

It’s been solved, I’ve doubled the layout that the controller of view used, then I installed the element in the layout that the view used, and not in the view. Then I changed the pages I didn’t want to use the layout to the layout duplicated (without the element), and now it’s running clean.

  • 1

    it would be interesting to put this as a comment on your question, after all this is not an answer, but then I really understood what you need, soon put an answer.

0

You can get the name of the current page on $this->name (in the view);

After that you create a array with every page where the element will not appear and does a check before calling the element in his view;

// 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');
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.