twig 相关问题

Twig是一款适用于PHP的现代,快速,灵活且安全的模板引擎。为Symfony创建并由Drupal 8采用。

我在使用全局工作线程和异步时遇到 PDF.JS 错误

我的 pdfjs 脚本有问题。 我第一次尝试,收到以下消息: 已弃用的 API 用法:未指定“GlobalWorkerOptions.workerSrc”。 未捕获的异常:未定义 所以我

回答 2 投票 0

如何在 twig.html 文件中加载以下 sulu 片段

我已经使用 sulu(无头 cms)创建了以下社交媒体片段,现在我想在我的 twig.html 文件中使用它。唯一的问题是我不明白我使用哪些变量来获取它

回答 2 投票 0

无法找到模板 Symfony 4

当我从Symfony 3.4更新到Symfony 4并用浏览器显示系统时,出现以下错误。 更改视图目录是一项繁重的工作,我不想做那么多

回答 2 投票 0

如何在 symfony 6 中为所有英语语言添加两个字母 gb 标志?

我使用 symfony 6 和 intl 包(也是 intl-extra)设置了翻译,一切正常,现在我想添加切换语言的功能,所以我已将其添加到我的 twig 模板中。 ..

回答 1 投票 0

如何覆盖购物车页面上的`storefront/component/line-item/element/label.html.twig`?

想要覆盖购物车页面上可用的店面/组件/行项目/元素/label.html.twig 文件。 我尝试在覆盖树枝模板中添加以下代码,然后它抛出错误......

回答 1 投票 0

Shopware 6:如何覆盖购物车页面上的`storefront/component/line-item/element/label.html.twig`?

想要覆盖购物车页面上可用的店面/组件/行项目/元素/label.html.twig 文件。 我尝试在覆盖树枝模板中添加以下代码,然后它抛出错误......

回答 1 投票 0

如何在没有 Twig Extension 的情况下在 Symfony 中检测移动设备

我一直在寻找一个简单的解决方案,如何在不使用扩展的情况下在 Symfony Twig 中确定移动设备。我到处都看到人们建议使用 twig 扩展或 javascript,比如......

回答 1 投票 0

用给定的发送到javascript来填充select2

在一个应用程序中,我在 EntityType 中创建了一个带有字段(选择)的表单,然后将其传递给 select2,没有问题。 树枝视图看起来像所有已保存助手的数组,您可以修改他...

回答 1 投票 0

尝试使用twig功能时Twig环境未注入shopware 6.5.4.0如何解决

我正在开发一个自定义插件,它接受来自 api 的数据。 我正在尝试使用 twig 函数来获取数据,如下所示 树枝功能类: 我正在开发一个自定义插件,它接受来自 api 的数据。 我正在尝试使用 twig 函数来获取如下数据 twig功能类: <?php declare(strict_types=1); namespace Nst\Twig; use Nst\Service\StoryblokService; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; class StoryblokTwigExtension extends AbstractExtension { public function __construct(private StoryblokService $storyblokService) { } public function getFunctions(): array { return [ new TwigFunction('get_story', [$this, 'getStory']), ]; } public function getStory(string $slug): array { return $this->storyblokService->getStory($slug); } } 也在我的服务中: <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services"> <services> <service id="Nst\Service\StoryblokService" public="true"> <argument type="service" id="Storyblok\Client"/> </service> <service id="Storyblok\Client" class="Storyblok\Client"> <argument>%env(dumpcode)%</argument> </service> <service id="Nst\Storefront\Controller\CodesController" public="true"> <argument type="service" id="twig"/> <call method="setContainer"> <argument type="service" id="service_container"/> </call> </service> </services> </container> 然后在我渲染页面的控制器中,我尝试注入到我的构造中以供使用。 <?php declare(strict_types=1); namespace Nst\Storefront\Controller; use Shopware\Storefront\Controller\StorefrontController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Twig\Environment; /** * @Route(defaults={"_routeScope"={"storefront"}}) */ class CodesController extends StorefrontController { public function __construct(Environment $twig) { $this->twig = $twig; } public function setTwig(Environment $twig): void { $this->twig = $twig; error_log('Twig has been set.'); // or use your preferred logging method } /** * @Route("/mystore", name="frontend.example.example", methods={"GET"}, defaults={"_routeScope"={"storefront"}}) */ public function showPage(): Response { if (!$this->twig) { error_log('Twig is not set.'); } return $this->renderStorefront('@Nst/storefront/page/example.html.twig', [ 'example' => 'Hello world' ]); } } 我的 twig 页面的副本,我需要这个 twig 函数来显示从 api 消耗的数据。 {% sw_extends '@Storefront/storefront/base.html.twig' %} {% block base_content %} <h1>Our example controller!</h1> {% endblock %} {% set story = get_story('ola-landing-page') %} {% if story %} {# Display your story content here #} {{ story.content.title }} {# Add more fields as required from the story #} {% endif %} 但我不断 hp.CRITICAL: Uncaught Error: Too few arguments to function Nst\Storefront\Controller\CodesController::__construct(), 0 passed in Uncaught PHP Exception Shopware\Storefront\Controller\Exception\StorefrontException: "Class Nst\Storefront\Controller\CodesController does not have twig injected. Add to your service definition a method call to setTwig with the twig instance" at 我不知道该怎么办,已经坚持了很长时间,请帮忙 您可以通过添加needs_environment选项并将其设置为true来自动注入twig环境,然后正确的实例将自动传递给您的TwigFunction <?php declare(strict_types=1); namespace Nst\Twig; use Nst\Service\StoryblokService; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; class StoryblokTwigExtension extends AbstractExtension { public function __construct(private StoryblokService $storyblokService) { } public function getFunctions(): array { return [ new TwigFunction('get_story', [$this, 'getStory'], [ 'needs_environment' => true), ]; } public function getStory(\Twig\Environment $twig, string $slug): array { /* Now you can use $twig to render something or you could even pass it to the service if needed/wanted .... return $twig->render(....); $this->storyblockService->setTwig($twig); ... */ return $this->storyblokService->getStory($slug); } }

回答 1 投票 0

如何在twig模板中显示图像并充当Drupal的链接?

我的网站上的 .twig 文件中有以下代码 我的网站上的 .twig 文件中有以下代码 <a href="https://appointments.detailandsupply.com/easyappointments/index.php?service=14" style="color: lightgreen; font-weight: 600; font-size: 18px; text-align: center; text-decoration: underline;">Click here to schedule an appointment</a> 我有一个名为schedule.png的图像位于/files/中,并且希望将此显示为链接并删除“单击此处安排约会”文本。我该如何去做呢? 我尝试在“单击此处安排预约”部分添加<img src="{{ asset('files/schedule.png') }}"> 我添加了 alt 标签和 style="border: none;" <a href="https://appointments.detailandsupply.com/easyappointments/index.php?service=14" style="text-align: center;"> <img src="{{ asset('files/schedule.png') }}" alt="Schedule an appointment" style="border: none;"> </a>

回答 1 投票 0

Drupal主题安装错误及迁移问题

我的名字是 Shahzad,我是 Drupal 和 PHP 的新手。我需要对 Drupal 项目进行一些更改。我只获得了存储库。我需要社区的指导和解决方案。 谢谢

回答 1 投票 0

为什么 twig 模板在“dev”环境中使用 if 语句时会抛出未知的“dump”函数?

我有一个使用 Symfony3 的树枝模板,如下所示: {% if app.environment == 'dev' %} {{转储(学生)}} {% 万一 %} 但在“prod”环境中它会抛出此错误,如 va...

回答 4 投票 0

Shopware 6:Vue.js 中 sw-snippet-field 和 sw-media-field 组件的 sw-inherit-wrapper

我正在使用 Vue.js 在 Shopware 6 中编写自定义管理模块(插件配置)。 我遇到的问题是缺少显示 w...

回答 1 投票 0

如何删除 Twig 上数组中的重复项

如何在 Twig 上删除数组中的重复项? 我在树枝中有数组值,例如。 {{ 设置数组 = ["testA","testB","testA","testC","testB"] }} 我想删除重复的项目并仅使用...

回答 7 投票 0

如何从 symfony 中删除 twig?

我的项目不需要任何树枝功能或模板。 我把树枝从 作曲家.json 捆绑包.php 我删除了所有配置树枝文件(yml 文件) 我删除了 html temp...

回答 1 投票 0

如何在 Symfony2/Twig 模板中包含原始 HTML 文件?

我正在 Symfony2 中开发一个项目,我有几小段 html 需要包含在我的主要视图之一中。根据 Twig 官方文档,我应该能够简化...

回答 4 投票 0

Shopware 6:如何访问管理模块的 Twig 模板中的配置参数

我正在寻找一种访问管理模块的树枝模板中的配置参数的方法。我尝试通过以下方式访问它: {{ shopware.config.pluginName.config.fieldName }} 问题是在...

回答 2 投票 0

如何使用 Twig 检查 Shopware 6 中当前活动的类别?

我正在使用 Shopware 6 并且需要检查 Twig 条件中当前活动的类别名称? 像这样的东西: {% if page.header.navigation.active.category == '图书' %} 是的&... 我正在使用 Shopware 6,需要检查 Twig 条件下的当前活动类别名称? 类似这样的: {% if page.header.navigation.active.category == 'Books' %} <h1>yes</h1> {% endif %} 在产品详细信息页面上,可以在page.product.seoCategory中找到该类别。按名称检查类别: {% if page.product.seoCategory.translated.name == 'Books' %} <h1>yes</h1> {% endif %} 在所有其他页面上,您可以使用变量page.header.navigation.active: {% if page.header.navigation.active.translated.name == 'Books' %} <h1>yes</h1> {% endif %} 如果有人仍然活跃,我也有类似的情况,但我需要产品详细信息页面中的主要类别名称,例如我有一顶分配给“女性”类别的帽子,女性类别是衣服的子类别, 我试过这个: page.product.seoCategory.translated.name 但它返回子类别 有人可以帮助我吗?谢谢

回答 2 投票 0

检查(在 twig 模板中)Shopware 6 客户是否属于特定客户组

我知道这个Shopware 6 twig的状况: {% 如果 context.customer 已定义 %} 做表演 {% 万一 %} 但如何检查客户是否属于特定客户组呢?

回答 1 投票 0

尝试格式化 {$

尝试将该代码格式化为twig格式: <p>尝试将代码格式化为twig格式:</p> <pre><code><textarea class="form-control" name="email_review_subject_<?php echo $language['language_id']; ?>" ><?php echo isset(${'email_review_subject_' . $language['language_id']}) ? ${'email_review_subject_' . $language['language_id']} : ''; ?></textarea> </code></pre> <p>所以我尝试使用这种格式:</p> <pre><code><textarea class="form-control" name="email_review_subject_{{ language['language_id'] }}" >{{ isset({'email_review_subject_' . language.language_id}) ? {'email_review_subject_' . language.language_id} : '' }}</textarea> </code></pre> <p><strong>错误:</strong></p> <blockquote> <p>未捕获的异常“Twig_Error_Syntax”,消息为“哈希键必须 后跟冒号 (:)。意外的代币价值“标点符号” “。” (“标点符号”预期值为“:”)</p> </blockquote> </question> <answer tick="true" vote="3"> <p><pre><code>isset</code></pre>中不存在<pre><code>twig</code></pre>这样的东西。如果你想在 twig 中使用动态变量,你还需要访问特殊变量 <pre><code>_context</code></pre> </p>一些可能的解决方案,<p> </p><code><textarea class="form-control" name="email_review_subject_{{ language['language_id'] }}" >{{ attribute(_context, 'email_review_subject_'~language.language_id)|default('') }}</textarea> <textarea class="form-control" name="email_review_subject_{{ language['language_id'] }}" >{{ attribute(_context, 'email_review_subject_'~language.language_id) is defined ? attribute(_context, 'email_review_subject_'~language.language_id) : '' }}</textarea> </code><pre> </pre><p>小提琴<a href="https://twigfiddle.com/p8h4wn" rel="nofollow noreferrer"></a> </p> </answer> <answer tick="false" vote="3">我很确定你不能使用 <p><code>.</code><pre> 在 Twig 中连接字符串。尝试</pre><code>~</code><pre>,然后看这里:</pre>如何在树枝中连接字符串<a href="https://stackoverflow.com/questions/7704253/how-to-concatenate-strings-in-twig"></a> </p> </answer></body>

回答 0 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.