Questions tagged [templating]

Front-end Twig templates that can Craftily render markup, scripts, and styles.

Filter by
Sorted by
Tagged with
1
vote
1answer
24 views

Twig Template spits out jibberish when trying to access user-defined fields

I have an Entry called Groups (I'm wondering if this might be some sort of reserved word issue) and, with Twig, I can bring out the base fields of id and title with no issue but when I try to pull ...
1
vote
1answer
35 views

Decrease heading level if entry is descendant in Redactor

I am currently building a doc system with multiple levels. I have build individual entries, but I'd like to parse the whole documentation in one page. Currently, I'm doing it like this: {% set pages = ...
1
vote
1answer
25 views

Split string with multiple delimiters

Hi what is the best was to split a paragraph into sentences please? I can use: {{ content|split('.') }} but what if a sentence in the paragraph ends with a question mark or exclamation mark instead? ...
1
vote
1answer
13 views

in array not matching

I am probably doing something daft here, but tried multiple things to no resolution. I trying to find if a value is in an array but my test case doesn't match. {% if entry.applicationStatus == '...
0
votes
0answers
31 views

Debugging Craft CMS templates on Visual Studio Code

Is there a way to debug templates used in craft cms on visual studio code? I tried doing it but I just get this error: "${workspaceFolder}' can not be resolved. Please open a folder." Any ...
1
vote
3answers
68 views

CSS file not being read by other templates

So I am making a new craft cms website, I have my page entries linked to the template pages/_entry.html, which works fine. I then made another type of pages called news, linked to the template news/...
0
votes
0answers
22 views

Internal Server Error after upgrading from craftcms 2 to 3

I just upgraded from Craft 2 to 3.6.14 (latest). I was able to successfully to the upgrade. I am able to get into the admin and was even able to install the feed-me plugin. I ported over all the files ...
0
votes
0answers
33 views

Variable “entry” does not exist - error on homepage single entry

Relatively new to CraftCMS and getting Twig error "Variable "entry" does not exist" on my home page. Noticed another post said to leave URI blank which should fix but didn't. Just ...
1
vote
1answer
18 views

Use same handle for different fields on different entry types

I've got two entry types: blog and job. Each has a category field but different category groups: blogCategories and jobCategories. I would like to write a Twig include to accept either a blog or a job ...
1
vote
1answer
32 views

Get related variants from entry and then show products for related variants and then loop only the variants that are related in commerce

Struggling with this one. If anyone can help me...? I have a section of entries called Vehicles. In this I have a related Variants field type. This has many different variants that related to each ...
1
vote
2answers
40 views

Checking if a value is in an array of IDS - using a filter?

Is there an easier way to achieve this? Perhaps using a |filter function? {% set variantIds = [] %} {% for variant in product.variants %} {% set variantId = variant.id %} {% set variantIds = ...
1
vote
1answer
45 views

Search for assets containing a custom field

How can I search for assets containing a custom field? The field on the asset is called lang. When I use this code no assets are found. {% set folderId = craft.app.request.getQueryParam('folderId') %} ...
2
votes
3answers
46 views

TWIG dataUrl function for resized images

Craft provides the very nice TWIG function dataUrl(pathToImg) to inline images in e-mails. E.g. <img src="{{ dataUrl('@webroot/assets/img/logo.svg')" /> will base64 encode the image ...
1
vote
1answer
43 views

How can I make make the class of an entry link “active” if entry is the current url?

I'm currently using the below jQuery but it's buggy as it relies on looking for 'similar' URL and not the exact URL. Is there a way it can be done just using Twig? {% set mainNavigation = craft....
1
vote
1answer
46 views

Displaying Craft templates in external apps

I'm working on a site that is running Craft v2 and also has an installation of Simple Machines Forum (SMF). This has been fine using the approach outlined in this answer, i.e. $craft = include '/craft/...
2
votes
1answer
49 views

Showing and playing video's in Twig templates

I want to be able to upload and play videos on my Craft CMS website. I created a volume and field to hold these videos. So far so good, but whenever I want to output the video in a video tag I'm not ...
3
votes
1answer
217 views

Interpret TWIG's {% js %} as <script> in PHPStorm

Does anyone know how to get PHPStorm interpret {% js %} as <script> for correct syntax highlighting in PHPStorm? Background: I'am always doing this: {% js at endBody %} {% if false %}<...
1
vote
0answers
23 views

Craft 3 entry.author.getPhoto() is coming up null on template, but the author has a photo uploaded in the user > details section, any ideas why?

The site is utilizing a Servd bucket to store all assets. The backend shows a photo successfully uploaded to the user > details section, but does not provide a url in the entry.author.getPhoto(), ...
1
vote
1answer
30 views

Order of {% set %} tags changing output unexpectedly

I have a content builder matrix that I'm looping through to build my page. That code works with no problems. {% set content = entry.pageBuilder.all() %} {% for block in content %} {% include "...
1
vote
1answer
54 views

Load currentUser using Sprig with Blitz

I'm having an issue with Sprig + Blitz Caching. I'm trying to load a user image if currentUser exists, though I'm having an issue with the caching. Sprig is loading in the unregistered user photo when ...
1
vote
1answer
24 views

Output Channel entries on another page with a matrix block

I know im doing something small wrong but I cant see what at this point. I have a channel called 'testimonialEntries' and I want to randomly output one of these entries on seperate pages. I cant ...
1
vote
1answer
21 views

Maps plugin not rendering

I'm currently trying to implement a Google maps via Maps plugin: https://github.com/ethercreative/simplemap I'm following documentation entirely, using PRO version of the plugin. In the plugin ...
0
votes
2answers
50 views

Load Entry via Ajax

I'm simply looking to onClick load an entries content via Ajax. Thought I see a lot of mixed answers here on SO, some referring to Element API, Creating a Plugin and GraphQL. Is there a simple way to ...
1
vote
1answer
38 views

Open Entry in a Modal

Unsure how to go about doing this. I'm looking to open a related entry in a modal on the same page. In an area, I have a list of houses. On click, I would like the user to open a modal and load the ...
1
vote
1answer
118 views

Accessing array/object attributes in Twig

There are three methods for that: object.attribute object['attribute'] attr(object, 'attribute') How are these different from each other?
1
vote
1answer
103 views

Output javascript inside twig variable

I am using the Enupal Stripe Payments plugin to pass line items to Stripe. The line items get passed in an array. I want to use a javascript cart to hold the items in local storage, reformat that and ...
1
vote
1answer
18 views

Display Count of Entries posted today

I'm trying to display a notification badge on how many new entries were posted today only. But I cannot get the following to work. {% set timeAgo = now|dateModify('today') %} {% set ...
1
vote
1answer
33 views

Google Maps plugin - How to trigger an info window

I'm migrating Smart Map over to the Google Maps plugin, and I want to open a popup on button click. But it seems there is no JS method available to open an info window. Here's how it was done in Smart ...
1
vote
1answer
15 views

Front End Entry Form - Proper Syntax for Custom Fields

I'm working on a front-end entry form with custom text input fields. From the Entry Form knowledgebase docs, I read "Any custom field handles must be provided in a fields[] array like body is ...
1
vote
1answer
26 views

How can I make an entries query based on currentUser is author or relatedTo currentUser

My project requires a notifications area. I want to list all notification entries that were created by currentUser or sent to currentUser. I can do created by = craft.entries().section('thename')....
1
vote
3answers
39 views

Stop specific Twig template from rendering anything

If i want specific template to stop from rendering anything, I use if: {% if something %} HTML markup... {% endif %} This however requires wrapping whole Template in if which is not ideal for ...
2
votes
1answer
25 views

Loop over query results in a macro

I have a macro for form fields, including select: {% macro select(name, options) %} <select name="{{ name }}"> {% for key, value in options %} <option value="{{ key ...
1
vote
2answers
85 views

Twig Format Number Filter not working

Twig docs include a format_number filter, as of ver 2.12 My install shows Twig at ver 2.12.5, so should work, but throws a Twig Syntax Error: Unknown "format_percent_number" filter. This ...
0
votes
0answers
82 views

Why is my base installation of Craft 3 so slow on Azure App Services?

I am evaluating a few different CMS solutions for my company's new website. Everything about Craft looks great according to my research. After installing version 3 onto an Azure App Service Linux ...
0
votes
0answers
21 views

CSS and JS tags with custom version parameter

When using {% css '/path/to/file.css' %} craft adds a v= query parameter by itself so that it comes out like this: <link href="/path/to/file.css?v=1612895916" rel="stylesheet"&...
0
votes
0answers
11 views

Working with content of HTML <meta> http-equiv Attribute in extending main layout template

I am extending the meta of my main layout template in one page only, utilizing the technique explored in some depth here. How do I add an HTML block from template extension to main layout template? (i....
1
vote
1answer
18 views

JS tag is adding semicolons to my content

I'm trying to output matrix content to create a javascript for my gallery. When I wrap the output with the {% js %}tag each line has an extra semicolon at the end like this: { "src": "/...
0
votes
0answers
35 views

Cache not working

I'm having troubles with my site being super slow. It seems like caching isn't working. When I upload the site to a different server, everything seems fine. When I empty the template cache and load ...
0
votes
0answers
42 views

Email template error

In the logs, I have this error: 2021-02-01 18:00:04 [-][-][-][error][craft\commerce\services\Emails::sendEmail] Email template parse error for email “Order Submitted”. Order: “123456”. Template error:...
2
votes
2answers
80 views

How to modify the login panel

how can i modify the login html? I specifically want to add an image below the title.
2
votes
1answer
18 views

Query entries posted in the past month

I’m trying to show only entries for the created in the last month. I’ve taken this from the example in the docs but it ends up showing nothing. There’s 100% entries with a postDate in the last month. ...
0
votes
0answers
40 views

WebP transform >> AssetTransformException: Failed to generate transform with id of X

I'm trying to transform some images on my site from JPG to WebP. However, I am having a problem to do so on my production site. I get this error: 2021-01-27 16:13:40 [-][-][-][error][craft\errors\...
0
votes
0answers
30 views

How to develop API with TWIG

I want to develop an API within Twig template that will have PDO implementation to get data. My application will be using content through CRAFT. Is it possible to develop API with TWIG template? ...
1
vote
1answer
63 views

Issue on new craft (craftcms3) setups: vendor Twig can't read system variable

After installing craft through composer, setting up the database and running craft setup, I have a craft application ready to go. When I go to settings/general, I always get a crash with following ...
2
votes
1answer
41 views

Dynamic URI to load entry template

This may be asking the impossible, but I'm trying to do the following: Say I have 3 channels, Country, Region, and Town. Town has an entry field to select a Region, a Region entry has a field to ...
0
votes
0answers
34 views

Why aren't my images displayed on the homepage

Our homepage.twig is a section Our Matrix is called "angebote" (it's german don't ask :D) We created two entries for our matrix This is our Code inside the homepage.twig file for including ...
1
vote
1answer
28 views

Entries limited by date range

I'm trying to filter entries on the front end by a date range but no matter what I do I end up with no results, despite there being results in the, temporarily hard coded, date range I am using. {% ...
1
vote
1answer
48 views

Simple Product Listing Pages by Category Slug

I'm new to Craft and I'm trying to create very basic product listing pages based on Categories and I'm not sure where to start. First, it doesn't look to me like you can create separate templates for ...
1
vote
0answers
58 views

Creating a modal popup using CraftCMS and Twig

I've been looking everywhere, I'm trying to create a modal using a global but I can't seem to figure out where to start. JavaScript: $popUp = new Garnish.Modal($('#popUpModal('), $popUp.show(), $popUp....
1
vote
1answer
71 views

Custom sort order?

I have a page that displays musicians grouped by their musical instrument. I am outputting them grouped by instrument, but I have been asked to sort the instrument groups by a custom order specified ...

1
2 3 4 5
32