octoberCMS |在布局之间共享代码 [英] octoberCMS | share the code between layouts

查看:102
本文介绍了octoberCMS |在布局之间共享代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的默认布局上,我有很多AJAX handlers,但是对于我的项目,我需要创建具有相同布局但具有不同变量(客户端字段)的静态页面...

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)...

据我所知,我需要创建不同的布局以扩展default layout ...

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?

例如的.代码:

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

推荐答案

10月不支持布局继承,因此,确实需要为每个结构(可以具有不同的变量)创建一个全新的(单独的)布局文件. ).

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:

  • 每当您有重复的HTML(标记)代码时,都使用部分代码
  • 将AJAX处理程序封装到组件中.这些是可重用的,并且具有定义处理程序的能力.请注意,您不能在partials中定义处理程序,因此请不要将组件添加到partials,而是将它们安装在布局上.这要求您将组件添加到您创建的任何新布局中,但是我认为比使用代码复制方法更好.

这篇关于octoberCMS |在布局之间共享代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆