I have to following drop down list
{{ Form::select('selected_site', $select_sites, Input::get('selected_site')) }}
it works fine and I see the name is "selected_site" but how do I set the HTMl Id of the element? I find nothing on this in documentation.
Thanks!
There's one more argument:
{{
Form::select(
'selected_site',
$select_sites,
Input::get('selected_site'),
array('id' => 'yourid')
)
}}
In this last one you can add anything else you need, 'class', 'data-whatever', etc.
There are 2 ways to do this.
You can setup a Label using the Laravel Form builder and use the same name on the control associated with it. As per the documentation at http://laravel.com/docs/html#labels (take a look at the note under this section) After creating a label, any form element you create with a name matching the label name will automatically receive an ID matching the label name as well.
As answered by #antonio-carlos-ribeiro, the 3rd parameter of the control takes a list of options on which you can setup the additional attributes for the control.
Hope this helps...
Related
I can't figure out how to set up the links. I have created a collection. I need an creator to be automatically specified in that record when adding a record to the collection. How do I do that?
I've faced this problem...
I found the solution in the documentation:
need to add
"populateCreatorFields": true
in the file (strapi v3) /api/your-type-name/models/your-type-name.settings.json
in options object
like:
...
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true,
"populateCreatorFields": true
},
...
More information can be found at strapi documentation
Strapi does not support it by default. As mentioned in this form you can achieve it by editing the strapi's controller. But I will not recommend you to edit the strapi controller at all. Please avoid it.
There is a simple and better solution to this. You can achieve this by creating one to one relationship. Create an author table/collection. Make one to one relationship with your other collection. You can make it a required option as well. So whenever someone creates an entry they have to select an author from your already created collection of authors.
And now you can get relation in your API and use it wherever you want to.
As stated in my comment, Strapi (tested on v3) comes with a created by field. To ascertain the claim, the following steps can be followed;
Create a new content type. Here I am setting only one field, called test
Add an entry for that content type. Notice the last update and by field on the right.
Save and open the entry. The last update and by fields have been automatically populated.
We are using CAS to login to our Drupal instance. This is working correctly and displaying the correct user content (blocks etc. based on roles). What is not working correctly is the small snippet in the theme that says welcome . It keeps showing the previous user who logged in.
How do I set this in bigpipe?
The code looks like this in the theme: <span id="user_name">{{user.displayname}}</span>
Is there a way to tell bigpipe not to cache this?
This code snippet is on one of our twig files header.twig.html which is a partial.
I ended up putting this in a block, and just referencing the block section in the theme instead of just pulling that, then I used the block to be ignored for caching.
Thanks!
I used this post with other resources to solve a similar problem. We were including {{ user.displayname }} in a twig template for the header on all pages of our site. Some users were seeing other users' names in the header after signing in. We wanted to solve the problem while impacting caching as little as possible. Here, I share in detail what we did in the hope that it will help others. I'll use the specific names used in our code. Readers will need to adjust to their own names. (The code follows our prescribed format, so please forgive that it isn't standard.)
Step 1
Create a custom module. Custom module creation is covered adequately in other places, so I won't give details here. Our custom module is named rsc.
Step 2
Create the folder modules/custom/rsc/src/Plugin/Block and in it create a file named DisplayName.php.
Step 3
In the file DisplayName.php, include the following:
<?php
namespace Drupal\rsc\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\user\Entity\User;
/**
* A block to show the user's display name
*
* #Block(
* id = "display_name",
* admin_label = "Display Name"
* )
*/
class DisplayName extends BlockBase // The class name must match the filename
{
public function build()
{
$user = User::load(\Drupal::currentUser()->id());
return
[
'#type' => 'markup',
'#markup' => $user->getDisplayName(),
'#cache' => ['contexts' => ['user']]
];
}
}
Step 4
Clear the Drupal cache to make the new block available at Block Layout.
Step 5
Go to Admin > Structure > Block Layout and place the Display Name block in the Hidden Blocks For Referencing - Not Displayed section (bottom of the list on our site). In the Configure Block dialog, edit the Machine name to display_name to match id in the code above. Clear the Display title checkbox and save. Doing this makes the block available for use in twig templates.
Step 6
In the twig template for the header, replace
{{ user.displayname }}
with
{{ drupal_entity('block', 'display_name') }}
The drupal_entity function is part of the twig_tweak module, which we were already using. It allows insertion of a custom block into a twig template. If you're not using this module, you'll need to install it, or find another method of including a block in a twig template.
Step 7
Clear the Drupal cache to make the modified template take effect.
If you see anything about this that can be improved, please comment.
Wondering if it is possible to manipulate the output of a #yield in Laravel? In short I have a title in my child template that I would like to set some id's with to make them unique. I know I could just create another #section('id', 'asdf') but rather not have to worry users with that especially since the title has to be unique anyways...
Could not find anything that says this is possible?
Example (which fails) but what I am essentially trying to do:
id="{{Str::kebab(#yield('title'))}}-preview-tab"
#yield gets replaced with a PHP echo statement so that is not what you want. If you want the content of a section you can grab it from the View Factory:
$__env->getSection($name, $default)
Or even calling yieldContent:
$__env->yieldContent($section, $default)
So you could try:
{{ Str::kebab($__env->getSection('title', 'some default if you want')) }}
If you have any issues with that, try the yieldContent method.
I am trying to use output data that I have set up using the builder plugin through the Record Details component and running into some issues.
In my created plugin, Schools, I have Instructors (set up as a relation to an instructors plugin I created separately). It is possible to have more than one instructor, so they are store in the database as an array. Like so:
[{"instructor":"69"},{"instructor":"79"},{"instructor":"80"},{"instructor":"96"}]
The numbers represent the row ID of the instructor table
In my CMS I can pull all of the School info just fine into a partial (Builder Details), and can pull the array of instructors, but I am struggling to pass this array over to look up the ID and get the instructors information. My thought right now is to send it to another partial like so:
{% "school/instructor" insProfile = instructorID %}
The partial school/instructor is getting the ID just fine. I have included the Builder Details component and set it up with the following:
Alias: builderDetails
ModelClass: Instructors Plugin
Identifier value: insProfile
Key Column: id
Display Column: member_name
I am getting record not found results. I am confused as to how to set the Identifier Value to match the value I passed through my partial. I tried {% set identifierValue = insProfile %} before the {% set record = ... %} is run, but that did not work either.
I cannot use the :slug because that is already generating the content needed for the School page. In a TLDR, it seems I ultimately want to duplicate this function through another partial and a different tag.
Still learning October, so any help is appreciated.
I think the original post was a bit lengthy and ultimately what I wanted to do was pass a variable into a component. Such as:
{% component 'builderDetails' identifierValue=dynamicVar %}
This does not appear to work as the builder details component generates too far into page load to pick up the variable change.
Per the OctoberCMS docs, the best solution for me was to create my own component that would accept the variable before the page processed using onRender() function.
public function onRender()
{
// This code will be executed before the default component
// markup is rendered on the page or layout.
$this->profileID = $this->property('insProfile');
$this->ins = $this->getUserInfo($this->profileID);
}
This allows me to put my component in a partial, and request the partial with the variable 'insProfile'. The component will pick up the property insProfile before page/plugin generates and use that variable instead of the default.
I then set up another function to query the correct user info needed (getUserInfo)
It would be nice if the builder plugin components could be updated in such a way that I did not have to do this as the builder plugin is rather extensive out of the box.
Posting this in case anyone else comes along this problem and isn't sure where/how to pass a partial variable into a component.
I created (in admin) a selection field called color. Now I can't access it. When I run {$note.data_map.color.content|attribute(show)} it prints value. But I can't access it without attribute(show). What can I do?
eZSelection's content is an array, access the 0 key on content to get the value.
{$node.data_map.email_option.content.0}
don't forget you always have attribute_view_gui* which can help you quite a lot in these cases.
you can set the attribute to be information collector and collect that information from user.
*{attribute_view_gui attribute=$node.data_map.color}
You need to match the option array defined in your class attribute with the id of the selected option in order to get the value of it.
$node.data_map.color.class_content.options will contain all the options available (associative array with id and name values)
$node.data_map.color.content is an array containing the ids of the selected options (because this field can handle multiple selection).
Even if the {section} function is deprecated I'll suggested that you have a look at the default template rendering an ezselection attribute : design/standard/templates/content/datatype/view/ezselection.tpl
If you have "Multiple choice" type than you can do it like this:
{if $node.data_map.color.has_content}
{foreach $node.data_map.color.content as $colorID}
{foreach $node.data_map.color.class_content.options as $opt}
{cond($opt.id|eq($colorID), $opt.name, '')}
{/foreach}
{/foreach}
{/if}