itmundi / linkit
该包已被废弃且不再维护。未建议替代包。
Craft的链接字段类型
dev-master
2015-11-09 13:06 UTC
Requires
- composer/installers: ~1.0
This package is not auto-updated.
Last update: 2022-11-30 02:12:09 UTC
README
一个链接字段可以取代所有,适用于Craft CMS的多功能链接字段类型。
此插件添加了一个字段类型,可以链接到各种内容,Linkit目前可以链接到
- 条目
- 资产
- 类别
- 电子邮件
- 电话号码
- 自定义URL
并且它与Matrix配合得非常好!
字段设置允许您
- 配置每个字段可以链接到哪些元素。
- 为每个字段设置可用的条目/资产源。
- 允许字段设置自定义链接文本。
- 允许字段设置在新窗口中打开链接。
- 设置默认链接文本。
安装
要安装Linkit,请按照以下步骤操作
- 将linkit/文件夹上传到您的craft/plugins/文件夹。
- 从Craft控制面板转到设置 > 插件并启用Linkit插件。
- 创建并配置一个新的linkit字段。
模板使用
获取链接对象
{% set yourLink = entry.yourLinkFieldHandle %}
仅链接 - 输出预构建的HTML链接
{{ yourLink.link|raw }}
构建简单的自定义链接
<a href="{{ yourLink.url }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.linkText }}">{{ yourLink.linkText }}</a>
构建自己的
{% switch yourLink.type %}
{% case "entry" %}
<a href="{{ yourLink.entry.url }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.entry.title }}">{{ yourLink.entry.title }}</a>
{% case "category" %}
<a href="{{ yourLink.category.url }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.category.title }}">{{ yourLink.category.title }}</a>
{% case "asset" %}
<a href="{{ yourLink.asset.url }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.asset.title }}">
{% if yourLink.asset.kind == 'image' %}
<img src="{{ yourLink.asset.url('thumb') }}" />
{% else %}
<img src="thumb-{{ yourLink.asset.kind }}.png" />
{% endif %}
</a>
{% case "custom" %}
<a href="{{ yourLink.custom }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.linkText }}">
<i class="custom-link-icon"></i> {{ yourLink.linkText }}
</a>
{% case "email" %}
<a href="mailto:{{ yourLink.email }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.linkText }}">{{ yourLink.email }}</a></p>
{% case "tel" %}
<a href="tel:{{ yourLink.tel }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.linkText }}">{{ yourLink.tel }}</a></p>
{% endswitch %}
模板变量
每个链接返回一个包含以下内容的链接对象
{% set yourLink = entry.yourLinkFieldHandle %} // Get the link
{{ yourLink.type }} // Returns the link type - entry, asset, email, tel, custom
{{ yourLink.email }} // Email String / False
{{ yourLink.custom }} // Custom URL String / False
{{ yourLink.tel }} // Telephone Number / False
{{ yourLink.entry }} // Entry Object / False
{{ yourLink.category }} // Category Object / False
{{ yourLink.asset }} // Asset Object / False
// Each link type is returned - only the active type will return data the rest return false
{{ yourLink.text }} // The Custom Text String
{{ yourLink.target }} // True/False (Bool) - Open in new window?
{{ yourLink.url }} // The full url (correct prefix added eg mailto: or tel:)
{{ yourLink.linkText }} // The link text string ready to use (If no custom text is provided it generates it based on the link type)
{{ yourLink.link }} // Full link HTML ready to use
路线图
- 强制下载选项
- 重新设计返回链接数据的方式
- 改进对目标内容的处理 - 如果需要
- 更多验证选项
变更日志
0.9.1
- 修复:当字段之前已被保存并设置为单选类型时,输入字段无法正确显示。
- 修复:自定义文本返回错误。
0.9
- 新增:使用链接变量时不再需要使用|raw过滤器。
- 修复:当设置一个链接类型时,输入字段现在可以正确显示。
0.8.1
- 新增:当字段仅选择了一个链接类型时,隐藏“链接到...”选择框。
0.8
- 新增:类别支持
0.7
- 新增:默认文本 - 字段类型设置,为链接添加默认链接文本。
0.6
- 修复:返回已删除条目或资产的PHP错误
0.5
- 初始beta版本
许可证
版权所有 2014 Fruit Studios Ltd