leowebguy/lorem-ipsum

Craft 的 Lorem Ipsum 生成器

安装: 556

依赖: 0

建议: 0

安全性: 0

星星: 0

关注者: 1

分支: 0

开放问题: 0

类型:craft-plugin

2.0.0 2024-03-27 03:21 UTC

This package is auto-updated.

Last update: 2024-09-27 05:07:52 UTC


README

通过 @joshtronic 扩展 PHP Lorem Ipsum

安装

打开您的终端并进入您的 Craft 项目

composer require leowebguy/lorem-ipsum -w && php craft plugin/install lorem-ipsum

使用方法

该插件向 Twig 暴露以下方法

单词

{{ craft.lorem.w(1) }} >> 1 word
{{ craft.lorem.w(5) }} >> 5 words

句子

{{ craft.lorem.s(1) }} >> 1 sentence
{{ craft.lorem.s(2) }} >> 2 sentences

段落

{{ craft.lorem.p(1) }} >> 1 paragraph
{{ craft.lorem.p(2) }} >> 2 paragraphs

 

需要包装?只需使用 Twig {{ tag }}

{{ tag('p', { 
  text: craft.lorem.w(10), 
  class: 'text-center' }) 
}}

output >> <p class="text-center">lorem ipsum...</p>

使用 twig 工具

craft.lorem.w(10)|title << Uppercases the first character of each word in a string.
craft.lorem.w(10)|upper << Formats a string into “UPPER CASE”.
craft.lorem.w(10)|ucfirst << Capitalizes the first character of a string.
craft.lorem.w(10)|lower << Formats a string into “lower case”.

您也可以为 sentencesparagraphs 提供一个 tag

{{ craft.lorem.s(2, 'p') 

output >> <p>lorem ipsum...</p><p>lorem ipsum...</p>

 

非常适合数据模板备用!

{% set data = {
    heading: entry.heading ?? craft.lorem.w(6),
    copy: entry.copy ?? craft.lorem.w(32)
} %}

<div>
  <h2>{{ data.heading }}</h2>
  <p>{{ data.copy }}</p>
</div>