octoberCMS | share the code between layouts

北战南征 提交于 2019-12-12 03:45:47

问题


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}

回答1:


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.


来源:https://stackoverflow.com/questions/42821066/octobercms-share-the-code-between-layouts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!