I've a question about Drupal 8, again and again and again...
Today, I've two views displayed on my front page and this two views display two differents informations types (in the first : Last articles in a caroussel, in the second : Recents events like a calendar with date and little description).
So, I would like to know if it's possible to template those views differently (two types) ?
Template those with preprocess functions ?
Or
Template those with templates files and template each field of those views ?
If your template is not complex, you can simply add in your views a field of type Custom text.
In there you can write HTML, use your fields (replacement patterns) and even use twig for custom logic.
*Make sure you have all the fields you need hidden.
*Make sure the field "Global: Custom text" is the last field in the list.
Another way is to create a theme by following the naming convention (see the docs here
Related
I'm working on a website where I want to add the settings of my Slick Slider trough the data-attribute. This is possible with the 'data-slick' attribute. The format for this looks like this: data-slick='{"slidesToShow": 4, "slidesToScroll": 4}'.
In my WordPress CMS I'm using the plugin 'Data Attributes' to add data attributes to a Gutenberg Block. Trough this plugin all double and single quotes are converted to and therefor changes on the frontend to data-slick="{"slidesToShow": 4, "slidesToScroll": 4}"
This is not working. The Slick Slider doesn't use these settings.
Is there another way to add a JSON object into a data-attribute so it will work with the Slick Slider?
Thanks already for your help!
Kind Regards,
Nick
I think storing a JSON value in HTML is a bad idea. There are too many conditions which you have to take into consideration - backend returning page, WEB server encoding (it can add a custom encoding header), and browser compatibility. For this task, I'd prefer 2 ways: bitwise mask or simple function-for example, define a few data attributes -data-s1, data-s2, data-sn. In the JS code, add an array [ data-s1, data-s2, data-sn]. And finally, add a loop with an in-condition (if data.contains(element of array) - read and then parse the data inside of the attribute). I never worked with wordpress but for JS it is a easy task. If you need example write comment below. I can update my answer
I have been tasked with making our Sitecore MVC WFFM forms more mobile friendly by adding the HTML5 Input Type so that different mobile keyboards are displayed depending on what field type is active. Through research I have seen examples of doing so, but not for the MVC flavor of WFFM. I know that a custom field type will be required, but the only examples I have seen are for non-MVC forms. Has anyone gone through this exercise and found a solution?
The .cshtml files for the for the WFFM fields are available to be updated.
To change the view of a WFFM MVC field:
In the Content Editor, in the content tree, in the Simple Types,
List Types, or Complex folder (sitecore/System/Modules/Web Forms for
Marketers/Settings/Field Types) click the field type item that you
want to change the view of.
In the right pane, in the Data section, in the MVC Type field, find
the class name of the item that you want to change the view of.
In the \Website\Views\Form\EditorTemplates folder of your Sitecore
installation, find the .cshtml file that corresponds to the class
name from step 2. For example, for the CheckboxField class, the file
name and extension is: CheckboxField.cshtml.
Edit the relevant .cshtml file to change the view, in this case to set the input types.
Deploy the updated .cshtml files to your CD environment.
The underlying controller for the field can also be customized in necessary or custom field types can be created.
See the Customize an MVC field type article for more detail
I'm trying to make a template that shows the time it was placed. I tried this:
This is a template ({{<includeonly>subst:</includeonly>CURRENTTIMESTAMP}})
but when transcluded it would show up as This is a template ({{subst:CURRENTTIMESTAMP}}) instead of substituting the timestamp. I then tried
This is a template ({{{{{|safesubst:}}}CURRENTTIMESTAMP}})
but that didn't substitute it; the timestamp would keep updating. Next, I tried
This is a template ({{<includeonly>{{{|safesubst:}}}</includeonly>CURRENTTIMESTAMP}})
but no dice.
I know it's possible with {{#invoke:}} but I don't have that option. Could someone help me out?
Consider how templates are stored. If you recursively subst the template, the contents of the template are stored in the wikitext of the including page, with CURRENTTIMESTAMP replaced with the actual timestamp. If you do not subst the template, the wikitext will only contain {{MyTemplate}}, and the timestamp of the edit is not stored anywhere; when the the parser renders the article and encounters CURRENTTIMESTAMP, it will just use the current timestamp. There is no way around that, #invoke or not.
What you can do is make the timestamp into a parameter, so in the including page you would write {{MyTemplate|{{subst:CURRENTTIMESTAMP}}}} and then the timestamp gets stored in the page. You can create a wrapper template with that exact content so that users only have to type {{subst:MyTemplateWrapper}} which is a bit easier. You can even make the template show an error / add an error category when used without substing, although that's a bit more involved.
I want to store html components of my website in the database in order to let the user choose from a variety of components each time
for example :
one page styled html page with a navbar and about section that could be changed and other stuff , it's layout could contain the following :
<div id="nav-holder">
<!-- Nav html goes here -->
</div>
<div id="about-holder">
<!-- about section html goes here -->
</div>
<!-- other html stuff -->
My db now is structured to hold the template with it's possible components for each section , and is storing a 'text' in it's html column , and I am adding all my styling and scripting to one sheet and js file that is loaded for the whole layout.
Is there any best practice to store and render those components in my db ?
Edit :
My main purpose is to create a website generator with some customization , providing a set of templates that the user chooses and within one template he can customize his template by choosing different components (navs,about sections , ... )
Also I will grab the data from some place and fill it into those templates The user will not be able to modify the data here , it's ready already so there is no need to give the user the ability to modify the data that would be filled in the document
Is there any best practice to store and render those components in my
db ?
Yes, don't! For several reasons, the primary one being that you use your database to persistently store variables related to models. Not html. The place for your html is in your views, the place to make choices as to which html to show is in your controllers.
Other reasons include that reading your html from a database will slow down your apps responsiveness and Rails tends to make text from a database html safe, meaning it will not automatically behave as html. This is a security precaution as a very common attack is to insert 'bad' code into your database which then gets run when you recover it and supply it to an unsuspecting user.
Use partials. Reference section 3.4 of this Rails Guide
Save the users choices of components in the database. If he chooses navbar_23, you store that 9 character string in the database and on request, your template serves him the partial named _navbar_23.html.erb from your views folder.
For example, in your views folder, create a subfolder views/navbars, inside that place your variants of navbars. Partials start with an underscore and end with .html.erb
In your model, store the users choice of navbar in say user.navbar. Just the name, not the starting underscore or .html.erb
In your template;
render partial: "views/navbars/" + user.navbar
Rails will automagically add the underscore and .html.erb when it looks for the file.
I'm writing template documentation for a wiki and wanted to include a working example of the template. However, I wrote the template to auto-categorize various fields and the entire template itself is also auto-categorized.
This means if I simply call on the template, it will categorize the doc page...and because the actual template page transcludes the doc page, the template page will also be categorized.
Is there a way to prevent these categories from automatically kicking in?
Something like the following should do the trick. Wrap the categorization in your template inside a parserfunction:
{{#ifeq: {{NAMESPACE}} | Help || [[Category:Some_Category]] }}
This sets the category when the template is transcluded onto a page that is not in the "Help" namespace.
Another option is to allow a parameter such as demo to avoid including the category.
If you don't mind being slightly cryptic, you could do the category in the template as {{{cat|[[Category:Some_Category]]}}}; then specifying the parameter as {{my template|cat=}} will prevent the category inclusion.
I'm not sure if I understand the question completely (what is "auto-categorize various fields"?). I am assuming here that you want to show a template "in action" on a documentation page - without attaching some categories (those categories the documentation page usually attaches to articles using this template) to the documentation page.
So
<onlyinclude>[[Category:Some_Category]]</onlyinclude>
will not do the job - as the template is in fact included. Right?
Try passing a parameter categorize=false to the template to indicate that categories are not to be attached in this case:
{{#ifeq:{{{categorize|}}}|false||[[Category:Some_Category]]}}
The double pipe after "false" means: if(categorize==false) then (empty), else [[Category:Some_Category]] - i.e. it is an equivalent construction for if(NOT(categorize==false))...
Good luck and thanks for all the fish,
Achim