octoberCMS | share the code between layouts

Ad

enter image description here

On my default layout I have many AJAX handlers, but for my project, I need to create static pages with the same layout but with different variables (fields for client)...

So as I understand I need to create different layout's that extends the partials from default layout...

But there are some way to share the code between the layouts to prevent repeating?

Or, there are some way to create different variables on a layout to diferrent statics pages?

Ex. of var. code:

{variable name="tagline" label="Tagline" tab="Header" type="text"}{/variable}
{variable name="banner" label="Banner" tab="Header" type="mediafinder" mode="image"}{/variable}
Ad

Answer

Ad

October does not support Layout inheritance, so it is true that you need to create an entire new (separate) layout file for each structure (which can have different variables).

To reuse code, you can follow a few approaches to achieve this:

  • Use partials whenever you have duplicate HTML (markup) Code
  • Encapsulate your AJAX handlers into components. These are reusable and have the ability to define the handlers. Please note, that you cannot define handlers in partials, so don't add components to partials, but mount them on your layouts. This requires you to add the components to any new layout you create, but I think you are better off than with the Code duplication approach.
Ad
source: stackoverflow.com
Ad