Hot answers tagged

42

The cleanest way I have found to achieve this is to create a generic template for the structure as well as a custom template for each entry that needs one, ensuring that its path matches the entry's uri. I then put this single line of code in the structure's selected template and it works beautifully: {% extends [entry.uri, '_generic'] %} This should ...


13

Is the registerSiteRoutes hook what you're looking for?


7

Your example code attempts to create a new Redactor instance, which (as Brad says) won't work inside the control panel (where Craft has created the Redactor instances already). You can, however, use the Redactor config files to add an element with the classname .note. To do that, add the following to the file config/redactor/Standard.json (or if you ...


7

Depends on how you want to determine "most popular"... If you want to calculate based on page views, then check out Ben Croker's Entry Count plugin (as Brad mentioned in his answer). If you want your users to vote on most popular, then check out my Upvote plugin, designed to emulate Stack Exchange or Facebook "likes".


5

Currently, the conditional redirect is the best way. You can use it to load a template dynamically in the structure's generic _entry template using the include tag. My suggestion would be to add a lightswitch field that tells the entry to load a custom template. Then in the _entry template do something like this: {% if entry.customTemplate %} {% ...


3

There's a special loop variable available in for loops which provides info about the iteration. In your case you'd just insert that list item after the 2nd iteration: {% for entry in entriesOnPage %} <li class="class-A">{{ entry.title }}</li> {% if loop.index == 2 %} <li class="class-B">I'm am different</li> {% ...


3

I believe you are looking for the Assets Field


3

I just came across this question, for the sake of up to date info for others, it is now possible to do this with the latest release(1.7) of the ContactForm plugin from Pixel & Tonic: https://github.com/pixelandtonic/ContactForm <input id="fromCompany" type="text" name="message[fromCompany]" value="{% if message is defined %}{{ message.messageFields.['...


3

In Craft 2.5 with Contact Form 1.4 I'm receiving the same error when using: {% if message is defined %}{{ message.contactTel }}{% endif %} I've gotten around this by using the Craft Request method getPost which can return a post value from an array. In the case of the original question, the following should work: <label for="fromCompany">Company:<...


2

Nothing native, but you could probably pull it off either with this plugin or something similar to it.


2

In Craft 3, you can accomplish this by hooking into the UrlManager::EVENT_REGISTER_SITE_URL_RULES event.


2

Why do you want to let them register twice? Maybe re-think the way you go about this: Possible solutions: Add them to a certain user group (via a plugin) on registration with the appropriate permissions and/or... ...if you don't want to write a plugin, you can add a certain category to the user element on registration. You can than check throughout your ...


2

Currently not possible, but I really like the idea of a plugin being able to swap out what craft()->search points to, whether it's ElasticSearch, Lucene, etc. I'll add it to our internal list, but you might want to submit a public feature request for this as well.


2

The link you referenced is assuming that you've got full-control over the output/HTML of the page and you've already got an instance of Redactor up-and-running. In the context of Craft, the only place you have full control over is the front-end of your site, not the control panel. You certainly can include the HTML/CSS/JS to load Redactor on the front-end ...


2

The problem with putting them in your templates folder is now PHP/Craft is going to try and serve them. Meaning that you've got the overhead of PHP and Craft when trying to request every single asset instead of if they were in the public folder where Apache can instantly serve them (orders of magnitude faster).


2

Whilst this mainly seems like a front-end development question, and Dr_Codswallop has perfectly summed up some steps in the comments to tackle that, as an answer for the Craft CMS specific side of the question there is a plugin I have used in the past that is very helpful, but it is only for Craft 2.x: Donkeytail I have had a look through the plugin store ...


1

To Create a user do $request = Craft::$app->getRequest(); $user = new User(); $user->username = $request->getBodyParam('username'); $user->email = $request->getBodyParam('email'); $user->newPassword = $request->getBodyParam('password'); $user->firstName = $request->getBodyParam('firstName'); $user-&...


1

I ended up using this code. {% set upcoming = craft.entries.section('section').order('customDate')%} {% for entry in upcoming %} {% if entry.customDate =='2018-10-12' %} {{entry.title}} {% endif %} {% endfor %} Works for now anyway.


1

You can use a Relation Field for each of your element types and include a custom js rule so if one of them has a value, the other one can't be selected. The more difficult way would be to extend the field and the ElementSelectModal and the ElementIndex to select multiple element types but this is going to be a little bit more tricky since you'll need a ...


1

The front-end of a Craft site is 100% custom and leaves you with complete control over the HTML, CSS, JS and images that are generated, so there's really no way for us to give you step-by-step instructions on how to make specific changes to the front of your site Generally speaking, you can modify the HTML and content of your site from the craft/templates ...


1

As Stephen pointed out, you're getting that error because your Commerce_GroupModel class is a Model that extends BaseModel, not an Element Type, which is what ElementsService->getCriteria() is looking for. Are you sure you actually need a custom element type here? Depending on what you're going for, Models might be enough.


1

Fixed it for now by including a custom enum class in the base plugin file: abstract class CustomElementType extends BaseEnum { const Badges_Badge = 'Badges_Badge'; } and then querying for the custom element in the plugin using craft()->elements->getCriteria(CustomElementType::Badges_Badge);


1

You could add a new entry type to your "example" section with a single field of type entries field and use that to "pull in" your special entry into your section. Within your entries loop you can check for the entry's entry type to switch classes: {% set class = entry.type == 'special' ? 'class-B' : 'class-A' %} or to include different template partials: ...


1

I think the short answer is yes, you do need a plugin to listen for events or tie into Craft's hooks. Luckily if that is all you need to do you can probably get away with writing a plugin that is only the singular plugin class file, you may not need any other plugin classes (models/records/etc). It seems as if you want to listen for onSaveEntry.


1

I think you are on the right track. Call the generic template _route.html, and have it do nothing but {%extends ...%} to route to the template you want.


Only top voted, non community-wiki answers of a minimum length are eligible