Questions tagged [twigextension]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
1answer
50 views

.first() vs. .one() in craft 3

I'm confused about the new .one() argument in craft 3 If I want to grab all entries I write: {% for entry in craft.entries.section('thing').all() %} {{ entry.title }} {% endfor %} Alls is nice ...
1
vote
1answer
22 views

Craft 3 CMS How to get all Channel Names/Titles

I am trying to retrieve all Channel sections' names/titles. This is snippet contains the troublesome part. {% set allSections = craft.entries.all() %} {% for section in allSections %} {% ...
1
vote
1answer
23 views

Custom field plugin: Unable to find template / General custom field plugin information

I am still relatively new to Craft CMS. I am trying to make a custom field plugin for Craft 3 but I am struggling to understand why I can't render my form template. The fieldtype should render a map ...
3
votes
2answers
177 views

How to access HTML input values from Twig and vice versa

I am new to Craft and Twig in general. I have encountered the following problems and struggling to find a solution for hours. I want to access the value of "foo" input field inside the twig ...
1
vote
1answer
50 views

Output raw html from if statement and combining strings?

I have the following code: <img{{ block.imageWidth|length ? ' width="' ~ block.imageWidth ~ 'px"' }} /> If imageWidth is specified as 120, it should output: <img width="120px" /> ...
1
vote
1answer
315 views

How to strip out src=“” value with twig from iframe code

I have have a text field for copy-pasting an iFrame code. <iframe src="https://webpagelink.com/l/3556456/2019-03-06/34576" width="100%" height="500" type="text/html" frameborder="0" ...
1
vote
2answers
38 views

TwigExtension added to Craft don’t work in emails

I added tomodomo/twig-pluralize-extension to my project composer, loaded with a custom module like that : if (Craft::$app->request->getIsSiteRequest()) { // Add in our Twig extension $...
1
vote
1answer
140 views

PHP eval filter for Twig

If I am confident in the users of our webpage that they will never be messing with the Twig templates, then what risk is there to creating a |php filter for Twig that just does this? {% set text = "...
1
vote
0answers
14 views

Recursive relations – how to build list properly?

I started building a list of recursive relations: We're in a project, we want to check interviews related to that project, see which persons participated in those related interviews, and then build ...
1
vote
1answer
39 views

UnexpectedValueException after loading plugin

I'm attempting my first Craft plugin and trying to update https://github.com/matthewattanasio/Craft-Url-Decoder-Twig-Extension for Craft 3 and followed the instructions in the docs for loading plugins ...
2
votes
2answers
36 views

How can I validate that I am passing an Asset into my custom twig filter?

I'm creating a custom twig filter in Craft 3 and am struggling with a really simple thing. {{ entry.backgroundImage.one() | filter }} In my filter, I would like to validate that I am being passed an ...
2
votes
1answer
207 views

Craft 3 - Fixing deprecation errors

I'm used to writing Twig 1 syntax, and since switching to Craft 3 (which uses Twig 2) I keep getting lots of deprecation errors in the control panel. Is there any reference material that provides the ...
2
votes
1answer
230 views

Craft or Twig converting html tags to alt characters

Just starting with plugin development. I modified the code from pluginfactory.io for a custom tag: public function navHTML() { $result = '<h2>Hello again</h2>'; return $result; } ...
2
votes
1answer
384 views

Register multiple TwigExtensions in one plugin in Craft 3

In my plugins init() function I have this: Craft::$app->view->registerTwigExtension(new TestTwigExtension()); If I duplicate that and change the Twig Extension class name, I just get an error:...
1
vote
2answers
428 views

Is there any way to create twig extension without a plugin?

I want to create custom twig extension without any plugin dependency. Is anyone has solution for this?
2
votes
1answer
317 views

How to get a list item <li> using a plain text field every time I hit enter

I'm trying to get a list from a simple plain text field which will accept line breaks. I need to find a way to wrap an li tag around the content on that line. So everytime I hit enter, it wraps <li&...
1
vote
1answer
162 views

Craft 3 Plugin: Saved image asset has no width / height

In my Craft 3 Plugin I am saving an image (YouTube poster) to an asset volume like this: $asset = new Asset(); $asset->title = $url; $asset->tempFilePath = $tmpPath; // temp path for image in /...
1
vote
1answer
579 views

Create Craft 3 Plugin - Call to a member function getVersion() on null

I'm trying to write my own Craft 3 TWIG filter / functions. For this purpose I created a scaffolding using pluginfactory.io. I did a composer require and composer correctly symlinks the plugin to the ...
1
vote
1answer
373 views

How do I add a new item or object to an existing object?

I'm using the Imager plugin and Craft for image compression. Currently, I have something like this: {% set imagerConfig = { jpegQuality: 80, pngCompressionLevel: 4 } %} In another part of my ...
1
vote
1answer
268 views

Cannot install custom Twig extension plugin

So I started building this plugin to add a twig extension to escape but leave &nbsp; intact. For some reason when I try install it or use it without the force argument on the import command in the ...
1
vote
1answer
158 views

Unable to load the “Craft\xyz” runtime after Craft update

After updating from Craft CMS 2.6.2973 to Craft CMS 2.6.2981 I get the following error message: "Unable to load the "Craft\xyz" runtime after Craft update" "Craft\xyz" is a Twig extension Fails in [...
13
votes
1answer
1k views

The Definitive Guide to Extending Twig in Craft CMS

So Craft's implementation of Twig is already very powerful and suitable to most common tasks. The Craft Docs already provide a great intro into using Twig and the handy extensions provided by Craft: ...
1
vote
1answer
106 views

How to retrieve the mode of an image transformation from its name?

I work on a portfolio with a large number of images with very high sizes and a lot of images transforms. The server on which this site is hosted reach these limits (images generations process are ...
1
vote
1answer
685 views

How do I print a value from Craft/Twig into a Javascript function?

I just want to print a value from Craft into a JavaScript function to filter a dashboard. The function is this: showOnly(filterName, values); I tried this: showOnly('Short Names','{{ entry.title ...
3
votes
2answers
196 views

Is it possible to extend twig with 'Twig_SimpleTest'?

I was on the Twig StackExchange forum and found an answer that suited my needs. But I can't for the life of me figure out how to implement this into a Craft CMS Plugin. I'm familiar with ...
4
votes
1answer
966 views

Creating sessions in Twig

I am trying to create the PHP $_SESSION equivalent in Craft CMS using Twig. I have searched very long and I can't find how you can create sessions in Twig. In previous posts I have found that I ...
4
votes
1answer
226 views

Is is possible to add a bespoke Twig template loader?

Twig lets you provide alternate (or multiple) template loaders. I'd like to take advantage of this to do use a bespoke loader to pull in components from a pattern library using a shorthand syntax like ...
0
votes
1answer
165 views

Path to plugin class from a Twig_Node

In my custom Twig tag I am trying to reference a class in the Twig_Node compile method, however I receive an error every time stating it can't find it. What would the path be to a custom plugin class ...
1
vote
1answer
581 views

Craft rich text field excerpt with slice and raw breaks when cut inside double tags

I got a rich text field. I made an excerpt with striptags slice and raw twig functions. It works fine most of the time (raw close tags when slice cuts inside a <p>). <div>{{ textBlock....
1
vote
1answer
91 views

Is it possible to target a fieldtype by it's Type name, rather than the handle name?

I've created an Asset Source and assigned my own field via the field layout. Then, I created an Assets Field to display a single image on a page. Using my plugins twig extension I can query the ...