Skip to main content

Questions tagged [templating]

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

81 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3 votes
0 answers
522 views

JsonLD & Schema

What is the best way to use Json-LD schema in the templates for Craft 3? I would like to dynamically load parts of the info. I know about the SEOmatic plugin but looking for a way to do it on my own.
Mforeman's user avatar
3 votes
1 answer
236 views

Using setTemplateMode on the frontend

I'm trying to access a CP template from the frontend, and i'm doing something like this in my plugin: <?php ... $oldMode = craft()->templates->getTemplateMode(); craft()->templates->...
Fred Carlsen's user avatar
  • 2,997
2 votes
0 answers
48 views

Asset Upload Form Field Error States

I currently have an asset upload field, but I'm trying to make it call errors back if the image isn't an extension that's set within the field, allowing users to understand why the form didn't save. ...
JMKelley's user avatar
  • 1,416
2 votes
0 answers
189 views

Add CP Tab content into include file

I am making a plugin where I have about 10 tabs at the top. Depending on the admin users privileges they may see a subset of 1-5 or 6-10 and super admins can see all 10. The issue I am running into ...
Chris's user avatar
  • 33
2 votes
0 answers
444 views

Craft\ConsoleApp and its behaviors do not have a method or closure named "getTheme"

I'm trying to render a template from a console command, but i'm getting the following error: Craft\ConsoleApp and its behaviors do not have a method or closure named "getTheme" The code looks like ...
Fred Carlsen's user avatar
  • 2,997
2 votes
0 answers
259 views

Setting template mode to CP doesn't let me load plugin templates

Setting template mode to CP with craft()->templates->setTemplateMode(TemplateMode::CP) only lets me load templates from app/templates. If i load app/templates/entries/_fields.html and I use ...
KnutSv's user avatar
  • 268
2 votes
0 answers
524 views

asset.getUrl() outputs double slashes

Craft hasn't done this prior (or maybe I just noticed), but I'm currently battling double slashes in URLs returned from {{ asset.getUrl() }}. The issue appears when I create an Assets field and set ...
Mats Mikkel Rummelhoff's user avatar
1 vote
1 answer
106 views

How to extend or override CP template?

I need to add some custom condition to the top siteMenu selector. Template file with top menu: vendor/craftcms/cms/src/templates/_elements/sitemenu.twig Block with this menu: vendor/craftcms/cms/...
DuxaBilii's user avatar
1 vote
0 answers
29 views

Craft 2 - Date Comparison In Criteria - Impossible to access an attribute ("today") on a string variable (">=")

I am working with a template in Craft 2, and I am setting up the criteria for entries to be displayed. Here is my code (below). {% set today = now|date('Y-m-d') %} {% set criteria = { section: '...
buck1112's user avatar
  • 400
1 vote
1 answer
245 views

Upgrading to 3.7.26 causes tempnam() error from twig's FilesystemCache.php

I am upgrading a Craft project that I have been neglecting for a little bit too long. I am upgrading to 3.7.26 from 3.4.25; on top of this, I am upgrading from PHP 7.1 to PHP 7.4. I'm also updating a ...
Rob Erskine's user avatar
1 vote
0 answers
57 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(), ...
user11767's user avatar
1 vote
0 answers
403 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....
Jayme Sinn's user avatar
1 vote
0 answers
35 views

Freeform output styling

When rendering the output of a single Star Rating field using the default Flexbox form, the output creates its own styling, overriding what I put in the element it's in... and adds a "float: left&...
M Smith's user avatar
  • 150
1 vote
0 answers
373 views

Is there a way to include partials in Craft without setting a path?

To separate code and avoid duplication I am trying to split up recurring pieces of twig code into partials (think of a nav or a block of services for example). I tried using include but Craft ...
ArneDB's user avatar
  • 11
1 vote
0 answers
31 views

EagerLoading on category pages with different product types

I have a category template like so; {% extends '_layouts/_site' %} {% set products = craft.products .with( [ 'department', 'productImage', 'finish', 'pcd', 'variants', 'thread', '...
Terry Upton's user avatar
  • 1,894
1 vote
0 answers
31 views

A user cannot change the password without completing the profile

I have an issue. I have custom fields in the user profile, some of them are required. I also have a change your password page and a change your email password. A user can create an account (Without ...
Jorge Anzola's user avatar
1 vote
0 answers
59 views

How can I find out what type of entry is getting used?

I have an include that is being used for plain entries, and is also being used for categories. (Categories have their own urls) {% if entry is defined %} {% set entry = entry %} {% elseif ...
Damon's user avatar
  • 4,706
1 vote
0 answers
439 views

Escaping rich text fields to json but keep html markup

I am trying to create an export from an old Craft2 site over to a new Craft3 site. The structure and fields are all different, so I figured the easiest way was to create a json file from my entries ...
Syversen's user avatar
  • 485
1 vote
0 answers
129 views

What the best strategy to test Craft template?

I would like to know if there is a way unit test templates using Craft 2.5? For example trying to prevent null pointers happening in production when an image is remove from the entry
jpoiri's user avatar
  • 231
1 vote
0 answers
3k views

Calling unknown method: craft\web\twig\variables\CraftVariable::embeddedAssets()

I get this message while trying to access embedded Asset with the plugin Embedded Assets 1.0.2: Calling unknown method: craft\web\twig\variables\CraftVariable::embeddedAssets() I was fiddling around ...
audeen's user avatar
  • 11
1 vote
0 answers
38 views

How to handle URLs of entries with no category?

I have a section where most entries have a category assigned to them, but a few ones have no category at all. I need help how to connect these entries' URLs to my entry template. So far I used a ...
Crafty Cat's user avatar
1 vote
0 answers
29 views

Entries sorted by title have some entries not alphabetical

I have the following code to return some grants, but whilst most of the entries are coming back alphabetically ordered, after the last "Z" entry, there are a few more entries also alphabetically ...
John's user avatar
  • 974
1 vote
0 answers
28 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 ...
Urs's user avatar
  • 639
1 vote
0 answers
305 views

Craft CMS 3 create custom field in plugin with two fields returning two values

I need to get two text fields under the same custom form and have it return two different values to be stored in the database. Right now with what I have, it's storing the same variable for both, ...
Mapbry's user avatar
  • 11
1 vote
0 answers
285 views

Categories and Sub Categories

Good morning and thank you in advance. Very to new Craft and Twig so I am not sure if I am coding this correctly but need some help. I have a forms center that has 5 main categories (Members, ...
Jason's user avatar
  • 107
1 vote
0 answers
62 views

Commerce: reading Stripe object in Craft Transaction model

I'm looking to add the credit card last four digits to my customer's frontend order history. Stripe is the gateway. The Stripe transaction object doesn't seem to be available in the Craft ...
biko's user avatar
  • 670
1 vote
0 answers
212 views

Access array from the static translation file

This is the scenario: I need the translations strings in both Twig and JS (For React). Of course I'm covered in the Twig part., and I don't want to maintain two different files (php and json). So I've ...
Jorge Anzola's user avatar
1 vote
0 answers
44 views

How to test if a address is on a list before it gets added? (MailChimp Subscribe Plugin)

I’m working on implementing this plugin: https://github.com/aelvan/mailchimp-subscribe-craft I’m wondering: How can I accomplish to test if an address is on the list before it gets added? And on top ...
Malte's user avatar
  • 215
1 vote
0 answers
57 views

Is this an ok approach to building a secondary navigation?

I have a site which has multiple menus e.g. primary and utility. I've built the menus via sections and the entry type for those sections has a title and a entry field. This site requires me to show a ...
mylesthe.dev's user avatar
1 vote
0 answers
187 views

Refresh "hidden" template after login with ajax

I am trying to create a seamless user login interaction with a modal form using ajax. Let's say I have a navigation template _navigation.html <div> {% if currentUser %} {{ currentUser }}...
krizajb's user avatar
  • 195
1 vote
0 answers
44 views

chain of random entries based on relations

I'm developing a bio section for a client. Every bio is linked to another bio creating a chain of bios. The order of this chain should be random. The schema would be as following: Bios: Bio a, Bio b, ...
Max Frischknecht's user avatar
1 vote
0 answers
265 views

making a dynamic menu in a template

Sometimes the links are in-page, sometimes they point outside. I want to be able to create an array menuitems that is passed to an include and which then generates a per-section index menu on the page....
bluppfisk's user avatar
  • 111
1 vote
0 answers
101 views

AMForms - How to use dynamic formHandle

I have a basic contact form set up and working but I've now got to change it to make it support locales. So depending on what language version of the website you are looking at, the form submits to a ...
Steve Holland's user avatar
1 vote
0 answers
60 views

When constructing an ECM, is it possible to compare two values?

My section has two numeric fields, lorem and ipsum. It's possible for users to enter any integer they want into these two fields. I want to grab all results where lorem is greater than ipsum. Here's ...
Lindsey D's user avatar
  • 24k
1 vote
0 answers
137 views

How to create an archive dropdown menu

How do I create a dropdown menu that filters all the posts into month and year, and then link to a template that has the entries of that month and year displayed? This is as far as I've gotten: <...
Ryan's user avatar
  • 11
1 vote
0 answers
29 views

Add jplist script to Craft CMS

I found this useful search, sort and filter script http://jplist.com, which I have added to my website. It works perfectly until I realize that when my database grow to the point it slow the page down....
William Spark's user avatar
1 vote
0 answers
98 views

Simpler way to code up a category conditional?

I've coded up conditional for categories. I'm still new to Twig and curious if there is a simpler way of coding the following. {% for feedItems in craft.entries.section('news').limit(null).offset(1)....
Tad Ward's user avatar
  • 317
1 vote
0 answers
190 views

Smart Map search not working with Province

I'm building out a store locator map and everything is going well. All store locations get output on the map and when I search with either a city or a postal code the map filters the results correctly....
CreateSean's user avatar
  • 1,983
1 vote
0 answers
136 views

I'm repeatedly setting the same variables. How to reuse code block to make this DRY?

I have a very complex layout which is requiring me to have quite a few {% for %} loops on the page and in each loop I need to set a bunch of variables. In order to make my template more DRY I was ...
Benek Lisefski's user avatar
1 vote
0 answers
146 views

How to get the order index of a structure entry?

I have a structure with 3 levels. The first 2 levels are for structuring the content and most of the content comes from the 3.rd level. This 3.rd level are the entries which are written by different ...
fab5's user avatar
  • 11
1 vote
0 answers
122 views

How do I get an input value to dynamically update a Craft query on each keypress?

I want to set a Javascript variable using a Craft variable. Is this possible? {% set searchJs %} $( "#search" ).keydown(function() { var query = document.getElementById('search').value; {% set ...
Büşra Başaran's user avatar
1 vote
0 answers
103 views

Where to find info on Entry URL Formats and routing syntax/options?

Is there any documentation other than on the CraftCMS web site with details and examples of Entry URL Format options/syntax? I came across an example from Brandon Kelly in this thread yesterday which ...
Britchie's user avatar
  • 215
1 vote
0 answers
55 views

Return Category from Inside Matrix

I'm having difficulty returning a category from inside a matrix block. So I'm returning a student based on a studentNumber variable {% set studentParams = { section : 'students', '...
andrew-caulfield's user avatar
1 vote
0 answers
3k views

How to get a param from an ajax request in twig?

Ok this has been puzzling me for too long now! I have some code that makes an ajax request: reqAjax: { type: 'get', url: '/mytemplatefolder/myfile.html', data: {town: 'bournemouth'} } ...
Lettie's user avatar
  • 2,033
1 vote
0 answers
530 views

Error with compiled Twig templates

Occasionally, after deploying Craft, without warning I am unable to access the admin dashboard and get the following PHP error: PHP Parse error: syntax error, unexpected '.', expecting '&' or ...
Tom McCarthy's user avatar
1 vote
0 answers
150 views

Implement a compare products funcionality

I´m working in a buggy´s website, and i want to implement a "compare" functionality, where the clients can check some products from the list ( a checkbox in each product ) and be able to compare the ...
Sebachenko's user avatar
0 votes
0 answers
21 views

Duplicated queries when using relations and assets

I have this setup: {% for entry in craft.entries().section('mySection').with(['relation.image']).all() {% set relation = entry.relation.one() %} {% set image = relation.image.one() %} {{ entry....
supazu's user avatar
  • 526
0 votes
0 answers
33 views

Any way to manually validate a CSRF token on the front-end?

I'm looking to manually validate a CSRF token (passed via GET) in a template, basically as a way of rate-limiting bots accessing a page which generates a CSV file. Poking around the Craft docs and ...
Derek Hogue's user avatar
0 votes
0 answers
21 views

Change layout of relations field in cp "Unable to find the template"

I've created a custom module that adds form submissions as relations to the entry they were submitted on. This functionality works, but I can't figure out how to change the template for the relations ...
Jane's user avatar
  • 11
0 votes
0 answers
45 views

twig how to include a twig in an existing div

My project now contain many twig and vue file, and I want to add a footer in every page. Every twig file will {% extends '_base/index.twig' %} so I want to include footer.twig in index.twig so that ...
LJ27's user avatar
  • 1