Zend Framework: Partials


/ Published in: PHP
Save to your folder(s)

`article.phtml` looked up in `views/scripts` by default. \r\n\r\ncan use `$this->partial(\"blog/article.phtml\", array(...))` to look for it in the `views/scripts/blog` folder too


Copy this code and paste it in your HTML
  1. // article.phtml
  2. <article>
  3. <header>
  4. <h2><a href="javascript:;"><?php echo $this->header; ?></a></h2>
  5. </header>
  6. <?php echo $this->body; ?>
  7. </article>
  8.  
  9. // view script
  10. // basic usage with array
  11. echo $this->partial("article.phtml", array(
  12. "header" => "This is a single post ...",
  13. "body" => '<p>rendered via <code>$this->partial()</code></p>')
  14. );
  15.  
  16. // passing an object with public properties
  17. $article = new stdClass();
  18. $article->header = "This is a \$article->header";
  19. $article->body = "This is the \$article->body ... ";
  20. echo $this->partial("article.phtml", $article);
  21.  
  22. // basic usage of partialLoop() with array
  23. echo $this->partialLoop("article.phtml", array(
  24. array(
  25. "header" => "This is a title",
  26. "body" => '<p>This is the body. rendered 1st post rendered via <code>$this->partialLoop()</code></p>'),
  27. array(
  28. "header" => "This is a 2nd article",
  29. "body" => "<p>This is the body</p><p>some more content</p>"),
  30. array(
  31. "header" => "Then the 3rd",
  32. "body" => "<p>This is the body</p><p>yet more content</p>")
  33. ));

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.