Questions tagged [templating]

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

Filter by
Sorted by
Tagged with
1
vote
2answers
19 views

Unable to find the template

I know this question has been asked multiple times. I have read all the post on this topic, and craft's docs. But still, I haven't figure out what I'm doing wrong. I would really appreciate a hand ...
2
votes
2answers
164 views

Get array of titles instead of whole collection of entries' attributes

I know that to get the entries I can do: craft.entries.all() but instead of getting the whole collection of entries, I would like to get an array of titles from those entries (or any other field). ...
1
vote
2answers
15 views

OrderBy section when selecting multiple sections in entries query

When getting pages from multiple sections like so: {% set aboutNavigation = craft.entries .section(['about', 'newsIndex']) .all() %} How can I set order that the sections appear? So I want ...
1
vote
1answer
20 views

Output Matrix field within Channel

Very new to craft and hence sorry if this is very basic. I have created a service channel which contains some matrix fields. One for a list and one for button. My approach here may be wrong and hence ...
0
votes
1answer
43 views

Improve performance and element queries when used multiple times

So I am building a mega menu and a separate set of templates for mobile. Both use the same set of element queries, which query two larger sections for pages and hierarchy. I am seeing quite slow load ...
1
vote
1answer
18 views

Blog pages returning HTTP 404 – Not Found – yii\web\NotFoundHttpException Template not found: blog/_entry

I’ve followed Craft’s instructions to set up the blog: https://craftcms.com/docs/getting-started-tutorial/configure/section.html When I published my first article, it returned a 404 error – see here: ...
1
vote
1answer
25 views

How to get rules of conditional fields values on front-end, using Reasons or another solution?

I'm building a front-end form, where I'm displaying on front-end my fields following their layout within the CP: {% set section = craft.app.sections.getSectionByHandle('handle') %} {% set ...
1
vote
1answer
39 views

Template URL/path alias

Is there any way to use an environment variable in the URL and template path settings for sections? We are prototyping a site with a temporary skin running alongside our front-end build but would ...
0
votes
1answer
20 views

How to get field widths when using getFieldLayout()?

I'm trying to show all my Channel's fields on front end, as they are shown on the CP: {% set section = craft.app.sections.getSectionByHandle('handle') %} {% set fieldLayout = section.getEntryTypes[0]....
1
vote
1answer
33 views

Loading JavaScript on Template Load

I'm working on a kiosk-type plugin which will cycle through all news entries, beginning upon template (or page) load. It needs to load a JavaScript ajax script for this on page/template load. Would ...
2
votes
1answer
24 views

Sorting Categories/Entries by # of relations dynamically

does anyone know if there's a way to display a type of "most popular categories" list? It's not exactly my use-case, but it's very similar Essentially, I want to be able to have users search ...
1
vote
1answer
30 views

Navigation Menu Options - drop downs and sticky?

I'm new to Craft CMS. It is possible to create a navigation menu with drop down menu items and a sticky menu bar on the desktop view please? How/where do I do this please? (Using Craft 2.7.10) ...
1
vote
1answer
23 views

What's the best strategy for products that are sold?

I wonder what's best practice for products that are sold? My strategy is to add a lightswitch "sold" and don't display sold products on the website and in the sitemap.xml, in the hopes that ...
0
votes
1answer
39 views

Regular Expression replace not working within Twig Template

I'm attempting to capture 4 attributes of an Attributes of an tag and injecting inline styles to the style attribute. Craft CMS and Twig templates are being used to generate HTML emails here, hence ...
1
vote
1answer
45 views

How can I pass a variable to Freeform's formatting template so that it's available to Twig?

I want to be able to toggle the display of a form's Title on or off, without having to resort to using a mostly-identical copy of the formatting template. Freeform formatting template: {% if ...
1
vote
1answer
20 views

Showing and hiding details (price, sale price, sku etc)when product variant is selected on details page

I currently have price, sku and variant title swapping when clicking between variants on a products details page. This works with AlpineJS and looks something this. https://codepen.io/amasci/pen/...
0
votes
1answer
42 views

Contact Form - Not sending emails

I am getting test emails but not contact form email? {% macro errorList(errors) %} {% if errors %} {{ ul(errors, {class: 'errors'}) }} {% endif %} {% endmacro %} {% set message = ...
1
vote
2answers
75 views

Merging classes in Twig based on component and context

Whats the best way to approach this in twig? So I have a component that is used in multiple places, so within this component I set some default classes like so: {% set navSidebarClasses = { heading: ...
1
vote
1answer
17 views

Creating a channel (or entries) using a similar channel

I am currently trying to make a channel called "classmates" similar to a channel that is called "News". I have this working beautifully, but I am not sure how to set a different ...
0
votes
0answers
25 views

Restrict Shipping Options to certain user groups - commerce

Craft 3.7.4 Craft Commerce Pro 3.4.0.3 Postie 2.4.8 I'm working on an inherited site which is my first using Commerce. I've been tasked with restricting shipping methods based on logged in user group ...
1
vote
1answer
25 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
37 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
63 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
17 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 == '...
1
vote
1answer
50 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
94 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
42 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
40 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
20 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
34 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
44 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
64 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
61 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
47 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
53 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
83 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
249 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
66 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
32 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
24 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
90 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
40 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
214 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
149 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
20 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
39 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
17 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
30 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
2 3 4 5
33