2

I like to overload the header partial at front-end. I have a module that customizes the header but it doesn't work. I tried using this one in index of my controller ->set_partial('header','header.html')

and I have my header.html in my module-name/views/header.html, the header which is in system/cms/themes/default/views/partials/header.html does not override which should be and I don't know what causing it. I've seen it in this discussion: here

My controller is in this case if for front-end (filename is same as the name of module) then the $this->template->set_partial('header','header.html'); doesn't work. Please help me as I started pyrocms a few days ago and a newbie web developer.

Any help is appreciated. Thanks!

NorthCat
  • 9,643
  • 16
  • 47
  • 50
Hendrick
  • 33
  • 5

1 Answers1

1

How did you include your header partial in the layout file of your theme? There are two ways: through the template or through the theme plugin.

If you want to be able to overload your header partial with $this->template->set_partial(), you need to include the header partial by using {{ template:partial name="header" }}.

If you would like to use your theme header and only use the injected header partial on some specific pages, you could do something like this:

{{ if {template:has_partial name="moduleheader"} }} {{ template:partial name="moduleheader" }} {{ else }} {{ theme:partial name="header" }} {{ endif }}}

And be sure to not use the same name for the partials (by this I mean filename and the name set in the set_partial functions). It won't work if you call it "header" in the theme and in the template.

And just as I wrote all of this, I've actually found a post on the PyroCMS Forums dealing with this: post on overriding theme partials in a module

Hope that helps!

mgrueter
  • 1,400
  • 6
  • 15
  • Hi! thanks for answering. Actually I tried `$this->template->set_partial()` in my controller and `{{ template:partial name="header" }}` in my view. It doesn't overload the header, instead it is placed in the body section of the webpage, and the default header is still there. So, there are two headers when I used it. – Hendrick May 07 '15 at 02:39
  • make sure that the partial you're injecting with `$this->template->set_partial()` has a different name than the theme partial - don't use 'header' both times. As for the appearance in the body, I would have to see your layout file to help you. But you might have put it in the wrong place. – mgrueter May 07 '15 at 06:38
  • My screenshot: [here](http://i.imgur.com/XrvDZ0E.png) my code in controller: `$this->template ->title($this->module_details['name'], 'the rest of the page title') ->set('items', $items) ->set_partial('headers','headers.html') ->set('items_exist', $items_exist) ->set('pagination', $pagination) ->build('index');` ------------------------------------------------------------------ my code in view: `{{ template:partial name="headers" }}` – Hendrick May 07 '15 at 08:25
  • I highlighted the picture because the logo is white and it cannot be seen so it became blue. – Hendrick May 07 '15 at 08:30
  • well, do you still have `{{ theme:partial name="header" }}` in your template? without the if/else construct I've posted above? – mgrueter May 07 '15 at 09:11