Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [templating]

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

1
vote
1answer
9 views

Can I have non-boolean TargetBlank output using HTMLPurifier and the Redactor plugin?

I'm using the Redactor plugin throughout a Craft 3 site and I'm also using a custom HTML Purifier config to clean up the HTML (surprise). { "HTML.ForbiddenElements": [" ", "br"], "...
1
vote
1answer
18 views

How can I load the templates from a module?

I'm creating a module that contains some predefined templates. How can I load them directly out of the vendor folder? I've tried doing Event::on(View::class, View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS,...
1
vote
1answer
18 views

Solspace Freeform upload multiple image files

I've had a good look around and can't find any template reference to uploading multiple images with Freeform. In settings i've allowed for 5 files in 'File Count'. I'm using the following template ...
1
vote
0answers
28 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 ...
1
vote
1answer
23 views

What variables are available to redirectToPostedUrl?

Craft's Web Controller has a redirectToPostedUrl method. Copied here for the sake of discussion: public function redirectToPostedUrl($object = null, string $default = null): YiiResponse { $url = ...
1
vote
2answers
17 views

Merging Assets Fields

I've got this working but it seems terribly verbose to do something, that in my opinion should be easier. Is there a better way to get the assets from 2 different fields, merge them and output them ...
0
votes
0answers
19 views

Interlacing progressive image transforms in templates [closed]

Is it possible to interlace image transforms directly within twig templates? There's a UI option for it in the CP but no mention of templating parameters in the docs
1
vote
2answers
20 views

Feed Me in Templates - can't pull in <itunes:summary>

I'm using Feedme to display content in my temmplates from a podcast RSS feed - not importing entries, just displaying. Everything is working fine except that I can't display the <itunes:summary>...
0
votes
0answers
15 views

Template 404 when receiving external POST data

I have a template which acts as the "thank you for booking" page for a tour company. However, the payment gateway sends the POST data along, and it's causing the template to 404 - even though there's ...
1
vote
2answers
32 views

Twig sometimes breaks JavaScript or CSS

Sometimes when your javascripts or stylesheets are formatted a certain way, twig seems to try and render those snippets (whom always include curly brackets in some way). For example, if you end you'...
1
vote
1answer
24 views

Trying to output contents of array

I'm trying to find a way of using php's print_r to output the entries that were pulled from the entries in the database. I'm pretty much brand new to Craft cms coming from Laravel, so a common thing I'...
1
vote
1answer
14 views

Craft 2 - Returning Value in Variable from Plugin to Template

I am working with a plugin and wish to return a value from it to the template that calls it. In my plugin, there is an XML feed call, and I would like to pass a value(variable) from the plugin to the ...
1
vote
2answers
31 views

Passing variables between sibling blocks

Is there any possibility to use "entry" from the for-loop inside the "main" block inside another block ("header" in my case)? See example below: {% extends "main" %} {% block header %} ...
1
vote
1answer
27 views

Craft 2, MySQL database, Twig, JavaScript files

I have created in Craft 2 CMS, under the profile of users (ex. parents), new tab for (children), where parents can fill in there children information. The data is saved in a database under the ...
1
vote
1answer
30 views

live and pending entries together not working

Craft 3.0.37 I have the following code which I expect to output all entries (live and pending) but it doesn't <ul> {% for entry in craft.entries.section('podcast').status('live','pending')....
0
votes
0answers
24 views

Incorrectly setting module template variable

Getting error: Calling unknown method: craft\web\twig\variables\CraftVariable::markAsReadModule() Trying to use a template variable that I created in my Craft 3 module, I use this module for ...
1
vote
2answers
118 views

Passing Twig Variable into Template from Include?

I'm trying to pass a variable value from an include into a template file. The variable is imageRatio. Within this include file I have the logic which sets the right image ratio. My goal with this is ...
1
vote
2answers
47 views

Live Preview for Upcoming Entries

I have an Events section on my site, and to display upcoming and passed events (entries with a status of pending or expired) I manually set the entry in the template: Where the URL is /events/my-...
2
votes
2answers
51 views

February always comes out as March - expect /yyyy/mm to be 2018/02 but it's 2018/03

This is a site that was recently updated from Craft 2 to Craft 3 and before the update this issue did not occur. Here is the code: {# all entries sorted by year/month #} {% set allEntries = craft....
2
votes
1answer
61 views

Twig replace filter - use part of regex match

Using replace filter we can match pattern using regular expressions, but can we use part of the matched string in the second argument of filter? For example, I want to match all numbers and replace ...
3
votes
2answers
51 views

Add a Leading Zero with a number field

I have a number field used for episode numbers and I would like to automatically add a leading zero when the number is less than 10. I have this working with a conditional but it seems inefficient. Is ...
1
vote
1answer
21 views

Get Entries from Every Site

How do I pull in entries from every site? I can't even seem to pass more than one argument to the .siteId parameter: {% set entries = craft.entries({ section: 'resources', siteId: [1,2,3], }...
3
votes
1answer
48 views

Dynamic Image Variant in Template

I'm keen to set my image variants dynamically from content editor and not quite sure how I do this in twig. I have three variants. They are named imageVariantsThumb, imageVariants16by9, and ...
1
vote
2answers
34 views

Updating Array Variable In Extending Template

I have a layout template: {% set bodyClass = [] %} <body class="{% for class in bodyClass %}{{ class }} {% endfor %}"> {{ block('pageBody') }} </body> And a template that extends it:...
2
votes
2answers
93 views

How to render plugin templates in Craft CMS 3?

I cannot find a way to render templates from a plugin controller in Craft 3. I feel as though I've tried every variation advised online but for some reason this still isn't working. <?php ...
0
votes
1answer
28 views

Partial links not going outbound

I have links on a partial within my templates, but it seems to be trying to load a template when it should just be loading the outbound href of the <a> tag. I don't have a clue why this would be ...
1
vote
1answer
19 views

Erros when using Entry Variable in craft.app.feeds.getFeedItems

I'm processing some feeds using craft.app.feeds.getFeedItems() and it works if I pass the limit as a hard coded number like this: {% set items = craft.app.feeds.getFeedItems(entry.rssURL, '5') %} <...
2
votes
0answers
16 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. ...
2
votes
1answer
11 views

Including a variant segment in product type template route in Commerce 2

Is it possible to use a wildcard when specifying the template path for a Commerce 2 product type? I want to format my URLs as /type/product/variant Where 'variant' could be a custom field applied to ...
0
votes
1answer
40 views

Using Label instead of Value from Dropdown

I currently have this dropdown on a front-end form, the problem I'm having is that it's saving the value where I really want to use the label in my templates such as United Kingdom instead of ...
2
votes
2answers
23 views

How can I add Google MarkerClusterer library to Smart Map?

I started to work with Craft CMS a couple month ago, I have a client that wants to have a clustered map, I went over Smart Map documentation but I couldn't find anything about on how to add Google ...
0
votes
1answer
39 views

Displaying related image assets from another section with twig

I have a site that shows upcoming football matches in a table, and I would like to include the clubs' logos next to each club name. I have the following sections and entry types, both generated using ...
1
vote
1answer
19 views

Front End Entry Form Select Dropdown Error

My front-end new entry form works, but when I add the complexity of a dropdown to the mix - it error's and doesn't save the entry. (I found this out with trial and error, removing fields until I found ...
1
vote
1answer
48 views

How do I setup the Login Page to work with requireLogin?

I want to create a login page. It would be a Single. The URI is set to login. So how do I name and map the twig file? I tried: creating a login folder under templates. naming the twig file ...
1
vote
1answer
29 views

Rendering HTML Heading Elements in Twig

I am rendering some headings using twig and want to know if there is a better and more readable way of doing the following... <{{ block.headingType }} class="measure-wide">{{ block.headingText }...
1
vote
1answer
24 views

Structure listing order & classes based on lightswitch value

I have a structure called "Projects", which I am currently listing on a page. The layout looks like the below - with the every row starting or finishing with a .wide class thumbnail: This is the code ...
1
vote
1answer
22 views

Access Default User Photo

I'm calling user photo's from my template, but it error's out when trying to obviously call a user photo which is empty. What I'm trying to achieve is if there is no user photo, use the default ...
1
vote
1answer
34 views

Updating User Photo from Front-End

I have this form, there's no errors getting thrown and the User photo field is not updating via this form. <form method="post" accept-charset="UTF-8" enctype="multipart/form-data"> ...
1
vote
0answers
34 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 ...
1
vote
3answers
56 views

Delete Entry from Front End

I have this form <form method="post" enctype="multipart/form-data"> {{ csrfInput() }} <input type="hidden" name="action" value="entries/save-entry"> <input ...
1
vote
1answer
45 views

Variable “entrySlug” does not exist Routing

I currently have a routing set up as follows to enable an "Edit" entry page following on from this question but I'm getting the following error message when going to that page. Variable "entrySlug" ...
1
vote
2answers
60 views

Edit Entry Page

I currently have a freeform which allows logged in users to create an entry from the front end. I'm looking to build an edit page for each of these entry's so the user can come back and edit it if ...
1
vote
0answers
28 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
1
vote
1answer
26 views

Translating checkbox labels

I'm trying to translate the labels for a global checkbox field in my front-end templates like in this post: Is there a way to have checkbox field labels translatable?. This looked promising but I can'...
1
vote
1answer
50 views

How do I fix a deprecation error for DateTime::year?

I am trying to work through deprecation warning. I have not touched Craft in a few months, so I am a bit rusty. The Deprecation Message is: DateTime::year is deprecated. Use the |date('Y') filter ...
1
vote
1answer
35 views

Craft CMS 3 Boilerpoint Web Project Setups Available?

Does anyone have any recommended boilerpoints or guides on setting up Craft CMS 3 with front-end tooling? Looking for an initial install to be setup properly with a preconfigured database, NPM, node....
1
vote
0answers
144 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 ...
0
votes
1answer
33 views

How do I assign a language to all datetime outputs

I am building a german calendar and am struggling having one language throughout all datetime outputs. The website is set to lang = de but the outputs of the solspace calendar is still english.
1
vote
2answers
72 views

Contact Form Setup on Craft CMS

I am just getting to grips with Craft CMS and am finding the Contact Form plugin tricky to use. I have built a reasonable site structure, figured how fields, sections, etc work at a relatively basic ...
0
votes
0answers
27 views

Only allowing users to change their own profiles

I have added public profiles following an answer on this stack exchange and it works great, the problem arises when adding a "User Profile Form" which allows users to update their own settings. The ...