toist-net / smarty_skeleton
使用 smarty 开发的基本主题,供设计师扩展
Requires
- smarty/smarty: 3.1.*
- symfony/debug: 4.2.x-dev
- symfony/http-foundation: 4.2.x-dev
This package is auto-updated.
Last update: 2024-09-22 20:02:55 UTC
README
这是一个用于构建与 toist.net 网站兼容的主题的框架。
目录
本包包含一组文件,用于帮助您创建主题。您需要特别注意 templates 文件夹,因为您正在创建的主题就位于此处,并且您需要将该文件夹的内容压缩成 zip 格式以发布您的主题。
所需文件
为了使主题被视为有效,它必须至少包含以下文件
- index_page.tpl
- index_content.tpl
- index_section.tpl
- index_list.tpl
index_page.tpl
此文件将用于显示网站页面。例如,网站的“关于我们”部分。
index_content.tpl
此文件将用于显示网站文章。
index_section.tpl
此文件用于显示网站首页。
index_list.tpl
此文件用于显示文章列表。
theme.json 文件
此文件的目的在于定义主题的资源。这不是必需的,但如果我们要添加多个文章、页面和部分的模板,或者如果我们要指定主题缩略图的存储位置,则必须添加它。以下是一个示例
{
"sections": [
{
"name": "Default home aspect",
"file": "index_section.tpl"
}
],
"pages": [
{
"name": "Default page aspect",
"file": "index_page.tpl"
}
],
"contents": [
{
"name": "Default article aspect",
"file": "index_content.tpl"
}
],
"lists": [
{
"name": "Default list aspect",
"file": "index_list.tpl"
}
],
"previews": [
{
"file": "previews/thumb.jpg",
"title": "The thumb",
"description": "This is the thumb that will be used on lists"
},
{
"file": "previews/home.jpg",
"title": "Home",
"description": "This is the home preview"
},
{
"file": "previews/page.jpg",
"title": "Page",
"description": "This is the page preview"
}
]
}
可用变量
section
网站中的一个部分,代表一个上下文。它将决定网站如何显示。想象一下部分就像封面(首页),它们可以通过特定的 URL 发布。让我们看看一个例子。假设您的网站有几个部分:游戏和电影。您可以通过以下 URL 访问它们:http://www.example.com/juegos/ 和 http://www.example.com/peliculas/。进入每个 URL,您可以看到不同的新闻列表、不同的幻灯片、不同的设计等等。
变量 section 用于访问当前上下文的全部数据。变量 section 展示的属性如下:title、domain、path、is_default、permanent_url、url_permanent、menus、contents。
section.title
保存部分的标题。以下是如何根据部分设置自定义页面的标题
{* usar la seccion para construir un titulo de pagina personalizado *} <title>{$section.title} - Example.com</title>
section.domain
用于访问当前部分的域名。例如,网站 example.com 可能定义两个部分“游戏”和“电影”,并分别在不同的子域名下展示,juegos.example.com 和 peliculas.example.com。
section.path
URL 中域名后面的部分是当前 URL 的路径(位于浏览器地址栏中),包括起始斜杠(/)。例如,在 URL https://example.com/una/ruta/en/el/sitio/ 中,path 指的是 "/una/ruta/en/el/sitio/"。
section.is_default
用于判断当前部分是否为默认部分。
section.permanent_url 和 section.url_permanent(两者)
此值表示通过它访问该部分(section)的完整URL。如果部分具有域名和路径,则两者的组合将给出部分的永久URL。请注意,当我们提到部分的永久URL时,我们指的是带我们回到该部分起始位置的URL。在该部分发布的所有内容都有自己的永久URL,该URL又包含了部分的永久URL。
section.menus
正如我们之前所说,一个部分(section)代表一个上下文。为了为网站的不同部分提供最大程度的个性化,我们可以根据当前所在的部分来定制菜单。因此,“main_menu”菜单可以根据我们所在的部分显示不同的菜单选项。让我们看一个例子。
{* usando $section.menus para acceder a los menus del sitio *} {if $section.menus.main_menu && $section.menus.main_menu.items} <div class="header-menu"> <header> <nav> {foreach $section.menus.main_menu.items as $menu_item} <li><a href="{$menu_item.href}" {if $menu_item.target}target="{$menu_item.target}" {/if}>{$menu_item.caption}</a></li> {/foreach} </nav> </header> </div> {/if}
section.contents
section.contents允许我们访问我们网站上的文章。它展示了在网站上定义的内容列表。默认情况下,存在四个列表:最新(latest)、特色(featured)、评论最多(most_commented)和查看最多(most_viewed)。还有用户创建的列表和基于类别的列表。让我们看一个例子。
{* mostrar los ultimos (usando la lista lates: section.contents.latest) 20 articulos publicados en la seccion actual *} {foreach $section.contents.latest->get(1, 20) as $content} <article class="post"> <figure> <img src="{$url->image_url($content.image_square_id, 200, 100)}" alt="{$content.title}"> <figcaption>{$content.title}</figcaption> </figure> <header> <time datetime="{$content.publication_date}">{$date->format('%d/%m/%Y', $content.publication_date_int)}</time> <h1><a href="{$content.permanent_url}">{$content.title}</a></h1> </header> <section> <p>{$content.description}</p> </section> <footer> <small>{$content.comments_count}</small> </footer> </article> {/foreach}
page 和 current_page
这些变量用于获取当前页码。当我们在显示文章列表时,它非常有用。
currentList
它展示了内容列表,其中包含当前页面正在显示的文章。
site
它展示了网站数据。通过这个变量,我们可以访问以下数据:language_iso_code、language_name、name、title、logo、site_title、company_email、company_name、company_phone、company_address、section、menus、contents。
lang
这个变量用于将主题文本翻译成我们网站的语种。
content
如果我们处于一篇文章中,这个变量将保存该文章的所有细节。让我们看一个例子。
<article> <header> <h1>{$content.title}</h1> </header> <section> {foreach $content.blocks as $block} {if $block.type == 'text'} <div class="text-block"> {$block.text} </div> {elseif $block.type == 'gallery'} <div class="gallery{foreach $block.display_options as $display_option} {$display_option}{/foreach}"> {foreach $block.images as $image} {if $image.link} <a href="{$image.link}"> {/if} <figure> <img src="{$url->image_url($image.id, 600, 400)}" alt="{if $image.title}{$image.title}{else}{$content.title}{/if}"> {if $image.description} <figcaption> {$image.description} </figcaption> {/if} </figure> {if $image.link} </a> {/if} {/foreach} </div> {elseif $block.type == 'title'} <h1>{$block.text}</h1> {/if} {/foreach} </section> </article>
辅助工具(Helpers)
辅助工具(helpers)是帮助我们(因此得名)执行特定和特定范围行动的对象。下面列出了可用的辅助工具。
date
我们用它来格式化日期。关于“date”辅助工具可用的完整选项列表,请参阅这里。为了提供更友好的日期格式选项名称,我们创建了一些别名。下面列出了这些别名。
- %year 等同于 %Y
- %year_short => %Y
- %month 等同于 %m
- %month_short 等同于 %m
- %month_name 等同于 %B
- %month_name_short 等同于 %b
- %day 等同于 %d
- %day_short 等同于 %#d (windows)
- %day_short 等同于 %e
- %day_name 等同于 %A
- %day_name_short 等同于 %a
- %hour_24 等同于 %H
- %hour 等同于 %I
- %hour_12 等同于 %I
- %minute 等同于 %M
- %second 等同于 %S
让我们看一个例子
... <footer> <small>Writed by John Smith at {$date->format('%d/%m/%Y', $content.publication_date_int)}</small> </footer> ...
url
这个辅助工具帮助我们创建URL。目前有三种方法:image_url、css_url 和 js_url。下面是一些例子。
创建一个宽度为200像素,高度为100像素的文章“square”图像的URL
<img src="{$url->image_url($content.image_square_id, 200, 100)}" />
包含我们主题的CSS和JS
<head> <link rel="stylesheet" href="{$url->css_url('css/style.css', $css_version)}"> <script type="text/javascript" src="{$url->js_url('scripts/main.js', $js_version)}"></script> </head>
ads
这个辅助工具仅用于方便地包含广告块。广告块由网站仪表板管理。
尝试包含一个宽度为900像素,高度为100像素的合适大小的广告块。
<div class="ad"> {$ads->get(900, 100)} </div>