title: Redirecting a URL

text:
# Question
Title: Redirecting a URL
I'm facing the following challenge:

I am setting up a homepage for our science department using OpenScholar, which is based on Drupal 6. From what I understand, it uses vsites so that many users can create personalized homepages on one OpenScholar installation.

I have set up OpenScholar on my server in the directory /var/www/example.com and it is served using a name-based VirtualHost on Apache2 that replies to the URL "example.com" ("example.com" is just a space holder).

When I created the homepage for my institute it is created at "example.com/example". The problem I am facing now is that I would like anyone calling "example.com" in their browser to end up at "example.com/example" without them even seeing "example.com/example" in their browser, in order to make the vsite my main site for "example.com". But I am not sure how to achieve this.

I have tried using Apache redirects/rewrites and also using the module "path redirect" and "global redirect" in Drupal, but it didn't work.

I would love to hear from someone on how this can be achieved.

------ EDIT ------

The answer by Tom Kirkpatrick did help, but I ran into a new problem. Here the setting I used:

```
  RewriteRule ^$ example/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
#  RewriteRule ^(.*)$ example/$1

```

I commented the last line due to the following: When I call example.com, I end up with example.com/example shown as example.com. But I have the problem that internal calls to page such as example.com/example/subpage is not changed to example.com/subpage. So if you continue browsing from example.com to a subpage in the browser you end up seeing example.com/example/subpage and not example.com/subpage, since that is the internal path that Drupal uses. That is also why I needed to comment the last line as this would rewrite example.com/example/subpage to example.com/example/example/subpage which does not exist. Or so I assume, because with it, it is not working. So is there some way to rewrite the path that the user sees in his browser from example.com/example/subpage (the internal path used by Drupal) to example.com/subpage without having to mess with the Drupal settings itself? I.e. to do it completely inside Apache? Thanks again!

# Answer
So If I understand you correctly, you want to be able to access the site that is currently at http://www.example.com/example, by a simpler http://www.example.com

Create a .htaccess file in the webroot with the following:

```
Options -Indexes
RewriteEngine On
RewriteRule ^$ example/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ example/$1

```

Then, update your settings.php file to have the $base\_url defined as: $base\_url = 'http://example.com';
> 2 votes

# Answer
As I understand the question, the user is having a problem with removing a subdomain from the url. He's in need of a way to redirect any request to a subdomain site to a standard url. The following technique may help, as it provides a way to redefine the base url, based on an element appearing in the url structure. (Know that with Drupal, the base url is position -1, the first element after the base url is position 0, etc. So that if you want to set a condition to check for an element in position 0 of the url \[www.base.com/position\_0\], as the code below does, you would write it to check for $path\[0\].

One of our Drupal 7 websites we maintain but did not develop has some code in the html.tpl.php that redirects pages with certain elements in the url position 0 to an alternate base url. I don't fully understand it but it's nice to know. Not sure if it's applicable to Drupal 6. Hope it helps somebody who needs a handy redirect method.

```
global $base_url;
$href = $base_url;
$path = drupal_get_path_alias($_GET['q']);
if ($path[0] == 'awards' OR strpos($_SERVER['HTTP_HOST'], 'awards') !== false) {
$head_title = $title . ' | Alternatesite.info';
$href = "http://www.alternate_site.info/";
$is_alternate_site = true;
}
else {
$href = $base_url;
$is_alternate_site = false;
}

```
> 1 votes

---
Tags: 6, redirection, uri
---


# Question
Title: How to contextual filter a view by a field value?
## QUESTION

I have an address field in my user form, from the address field module.

I have a content type named "project" which also have an address field and users can pick up a country related to the country the project will belong to.

I want to make a view filtering all the projects related to the logged-in user's address country field.

## TRY

My trick is to make a **user-view** with a author-content relationship filtered on the content type project. Now I have the two fields in the view, I'm trying to compare them with a contextual php filter.

I tried to use php filter based on this post

```
$node = node_load($data->nid);
$user = user_load($user->uid);

$field_user_country = field_get_items('user', $user, 'field_user_address_country');
$country_user = field_view_value('user', $user, 'field_user_country', $field_user_country[0]);

$field_project_country = field_get_items('node', $node, 'field_project_range_country_country');
$project_country = field_view_value('node', $node, 'field_project_country', $$field_project_country[0]);

if ($price_a = $price_b) {
  return TRUE;
}

```

The fact is *field\_user\_address\_country* is actually stored under *field\_data\_field\_user\_address* in the database.

Same for *field\_project\_range\_country\_country* which is stored under *field\_data\_field\_project\_range\_country*

What is the best way to do this ? Is what I'm trying to do possible ?

## UPDATE 1

Clear code which give me an ajax error :

```
$node = node_load($data->nid);
$user = user_load($user->uid);

$field_user_country = field_get_items('user', $user, 'field_user_address_country');
$country_user = field_view_value('user', $user, 'field_user_address_country', $field_user_country[0]);

$field_project_country = field_get_items('node', $node, 'field_project_range_country_country');
$project_country = field_view_value('node', $node, 'field_project_range_country_country', $field_project_country[0]);

if ($country_user == $project_country) {
  return TRUE;

```

## UPDATE 2

Here the new code which is still giving me an ajax error :

> EntityMalformedException : Missing bundle property on entity of type node

```
$node = node_load($data->nid);
$user = user_load($user->uid);

$field_user_country = field_get_items('user', $user, 'field_user_address_country');
$country_user = field_view_value('user', $user, 'field_user_address_country', $field_user_country[0]);

$field_project_country = field_get_items('node', $node, 'field_project_range_country_country');
$project_country = field_view_value('node', $node, 'field_project_range_country_country', $field_project_country[0]);

if ($country_user == $project_country) {
  return $country_user;
}

```

Have a bigger ajax error (like 15 lines) if I put

```
global $user
$node = ($node = menu_get_object()) ? $node->nid : NULL;

```

At the beginning of my code.

# Answer
> 1 votes
Create a block view of Show: content, in contextual filter add Country.

Add this to your view contextual filter:

```
  global $user; // gets current logged in user object

  if (isset($user->field_user_address[LANGUAGE_NONE][0]['country'])) {
    $user_country = $user->field_user_address[LANGUAGE_NONE][0]['country'];
    return $user_country;
  }

```

---
Tags: 7, entities
---


# Question
Title: Get URL path or node.id in views fields replacement pattern
I need to rewrite my view fields like:

```
<a href="{{ path }}">
 <div class="card-header">
   <h3 class="card-title">
     {{ title }}
   </h3>
 </div>
</a>

```

But if I click on *Add field* (in my view), `nid`, or `path` are not available? I have to construct my `<a>` link attribute like above markup. But how do I render the URL path to the node?

# Answer
> 1 votes
> But if I click on Add field (in my view), nid, or path are not available?

Did you create a view of Show: Content ? (re-using pic from other answer, look in view settings)

You probably selected something else, hence why those fields are not available.

So you could add a relationship of node content or create a brand new view again and this time make sure you select Show: content.

---
Tags: views, 8, path-aliases
---


title: copy image over image in Content body?

text:
# Question
Title: copy image over image in Content body?
I want to overlay an image over another in the Content body. How do I achieve this? I do not know much about coding or themeing.

Could someone guide me please?

Thanks

# Answer
> 1 votes
You can add your own CSS classes to the images via the WYSIWYG editor. The code provided on https://stackoverflow.com/questions/48474/how-do-i-position-one-image-on-top-of-another-in-html should do what you are looking for:

```
.parent {
  position: relative;
  top: 0;
  left: 0;
}
.image1 {
  position: relative;
  top: 0;
  left: 0;
}
.image2 {
  position: absolute;
  top: 30px;
  left: 70px;
}

```

```
<div class="parent">
  <img class="image1" src="https://placehold.it/50" />
  <img class="image2" src="https://placehold.it/100" />
</div>

```

---
Tags: theming
---


# Question
Title: Set Default Value of "commerce_addressbook_customer_profile_form" "first_name" field
I would like to set the first and last name field using hook form alter. I am already in the right form and able to dump the array you can see it below. This is the form 'commerce\_addressbook\_customer\_profile\_form':

The field I want to populate is this

https://screencast.com/t/OUkrOtpclfC

I am unable to set the value of the first and last name field. Here is the array when I print $form.

```
  Array
(
    [#parents] => Array
        (
        )

    [#entity] => stdClass Object
        (
            [type] => shipping
            [uid] => 1481
            [profile_id] =>
            [revision_id] =>
            [status] => 1
            [created] =>
            [changed] =>
            [is_new] => 1
            [_is_new] => 1
            [name] => ASDFASDF_1481
            [date] => 2017-02-06 23:04:06 -0500
        )

    [commerce_customer_address] => Array
        (
            [#type] => container
            [#attributes] => Array
                (
                    [class] => Array
                        (
                            [0] => field-type-addressfield
                            [1] => field-name-commerce-customer-address
                            [2] => field-widget-addressfield-standard
                        )

                )

            [#weight] => -10
            [#tree] => 1
            [#language] => und
            [und] => Array
                (
                    [0] => Array
                        (
                            [#entity_type] => commerce_customer_profile
                            [#entity] => stdClass Object
                                (
                                    [type] => shipping
                                    [uid] => 1481
                                    [profile_id] =>
                                    [revision_id] =>
                                    [status] => 1
                                    [created] =>
                                    [changed] =>
                                    [is_new] => 1
                                    [_is_new] => 1
                                    [name] => ASDFASDF_1481
                                    [date] => 2017-02-06 23:04:06 -0500
                                )

                            [#bundle] => shipping
                            [#field_name] => commerce_customer_address
                            [#language] => und
                            [#field_parents] => Array
                                (
                                )

                            [#columns] => Array
                                (
                                    [0] => country
                                    [1] => administrative_area
                                    [2] => sub_administrative_area
                                    [3] => locality
                                    [4] => dependent_locality
                                    [5] => postal_code
                                    [6] => thoroughfare
                                    [7] => premise
                                    [8] => sub_premise
                                    [9] => organisation_name
                                    [10] => name_line
                                    [11] => first_name
                                    [12] => last_name
                                    [13] => data
                                )

                            [#title] => Address
                            [#description] =>
                            [#required] => 1
                            [#delta] => 0
                            [#weight] => 0
                            [#type] => fieldset
                            [#handlers] => Array
                                (
                                    [0] => address
                                    [5] => name-full
                                )

                            [street_block] => Array
                                (
                                    [#type] => addressfield_container
                                    [#attributes] => Array
                                        (
                                            [class] => Array
                                                (
                                                    [0] => street-block
                                                )

                                        )

                                    [#weight] => 0
                                    [thoroughfare] => Array
                                        (
                                            [#title] => Address 1
                                            [#tag] => div
                                            [#attributes] => Array
                                                (
                                                    [class] => Array
                                                        (
                                                            [0] => thoroughfare
                                                        )

                                                    [autocomplete] => address-line1
                                                )

                                            [#size] => 30
                                            [#maxlength] => 255
                                            [#required] => 1
                                        )

                                    [premise] => Array
                                        (
                                            [#title] => Address 2
                                            [#tag] => div
                                            [#attributes] => Array
                                                (
                                                    [class] => Array
                                                        (
                                                            [0] => premise
                                                        )

                                                    [autocomplete] => address-line2
                                                )

                                            [#size] => 30
                                            [#maxlength] => 255
                                        )

                                )

                            [locality_block] => Array
                                (
                                    [#type] => addressfield_container
                                    [#attributes] => Array
                                        (
                                            [class] => Array
                                                (
                                                    [0] => addressfield-container
                                                    [1] => locality-block
                                                    [2] => country-GB
                                                )

                                        )

                                    [#weight] => 50
                                    [#maxlength] => 255
                                    [#attached] => Array
                                        (
                                            [css] => Array
                                                (
                                                    [0] => sites/all/modules/addressfield/addressfield.css
                                                )

                                        )

                                    [dependent_locality] => Array
                                        (
                                            [#title] => Suburb
                                            [#required] =>
                                            [#access] =>
                                            [#size] => 25
                                            [#maxlength] => 255
                                            [#tag] => div
                                            [#attributes] => Array
                                                (
                                                    [class] => Array
                                                        (
                                                            [0] => dependent-locality
                                                        )

                                                    [autocomplete] => address-level3
                                                )

                                            [#suffix] =>

                                        )

                                    [locality] => Array
                                        (
                                            [#title] => Town/City
                                            [#required] => 1
                                            [#access] => 1
                                            [#size] => 30
                                            [#maxlength] => 255
                                            [#prefix] =>
                                            [#attributes] => Array
                                                (
                                                    [class] => Array
                                                        (
                                                            [0] => locality
                                                        )

                                                    [autocomplete] => address-level2
                                                )

                                            [#tag] => div
                                        )

                                    [administrative_area] => Array
                                        (
                                            [#title] => County
                                            [#required] =>
                                            [#access] => 1
                                            [#empty_value] =>
                                            [#size] => 30
                                            [#maxlength] => 255
                                            [#prefix] =>
                                            [#render_option_value] =>
                                            [#attributes] => Array
                                                (
                                                    [class] => Array
                                                        (
                                                            [0] => state
                                                        )

                                                    [autocomplete] => address-level1
                                                )

                                            [#options] =>
                                            [#tag] => div
                                        )

                                    [postal_code] => Array
                                        (
                                            [#title] => Postcode
                                            [#required] => 1
                                            [#access] => 1
                                            [#size] => 10
                                            [#maxlength] => 255
                                            [#attributes] => Array
                                                (
                                                    [class] => Array
                                                        (
                                                            [0] => postal-code
                                                        )

                                                    [autocomplete] => postal-code
                                                )

                                            [#prefix] =>
                                            [#tag] => div
                                        )

                                )

                            [country] => Array
                                (
                                    [#title] => Country
                                    [#options] => Array
                                        (
                                            [GB] => United Kingdom
                                        )

                                    [#render_option_value] => 1
                                    [#required] => 1
                                    [#attributes] => Array
                                        (
                                            [class] => Array
                                                (
                                                    [0] => country
                                                )

                                            [autocomplete] => country
                                        )

                                    [#weight] => -500
                                    [#ajax] => Array
                                        (
                                            [callback] => addressfield_standard_widget_refresh
                                            [wrapper] => addressfield-wrapper
                                        )

                                    [#element_validate] => Array
                                        (
                                            [0] => addressfield_standard_country_validate
                                        )

                                    [#limit_validation_errors] => Array
                                        (
                                        )

                                )

                            [#wrapper_id] => addressfield-wrapper
                            [#prefix] =>

                            [#suffix] =>

                            [name_block] => Array
                                (
                                    [#type] => addressfield_container
                                    [#attributes] => Array
                                        (
                                            [class] => Array
                                                (
                                                    [0] => addressfield-container-inline
                                                    [1] => name-block
                                                )

                                        )

                                    [#weight] => -100
                                    [#access] => 1
                                    [first_name] => Array
                                        (
                                            [#title] => First name
                                            [#size] => 30
                                            [#maxlength] => 127
                                            [#required] => 1
                                            [#attributes] => Array
                                                (
                                                    [class] => Array
                                                        (
                                                            [0] => first-name
                                                        )

                                                    [autocomplete] => given-name
                                                )

                                        )

                                    [last_name] => Array
                                        (
                                            [#title] => Last name
                                            [#size] => 30
                                            [#maxlength] => 127
                                            [#required] => 1
                                            [#prefix] =>
                                            [#attributes] => Array
                                                (
                                                    [class] => Array
                                                        (
                                                            [0] => last-name
                                                        )

                                                    [autocomplete] => family-name
                                                )

                                        )

                                )

```

I tried these

```
 $form['commerce_customer_address']['und'][0]['#columns'][11]['first_name'] = "test";
 $form['commerce_customer_address']['und'][0]['#columns']['first_name'] = "test";
 $form['commerce_customer_address']['und'][0]['#columns'][11]['first_name'] = "test";
 $form['commerce_customer_address']['und'][0]['name_block']['first_name']["value"]['#default_value'] ='test';
 $form['commerce_customer_address']['und'][0]['name_block']['first_name']['#default_value'] ='test';
 $form["commerce_customer_address'"]["und"][0]["value"]['#default_value'] ='test';
 $form['commerce_customer_address']['und'][0]['first_name'] = "test";

```

and other variations but I am not seeing the value populate

For example this

```
$form['commerce_customer_address']['und'][0]['name_block']['first_name']['#title']='test';

```

Changes the title of the field to test, but I still can not set a default value to pre-populate the field on page load.

# Answer
> 3 votes
addressfield is not really a regular form. but uses an address object.

now there is a hook to set de default value, called *hook\_addressfield\_default\_values\_alter*, and you can set it like this:

```
function hook_addressfield_default_values_alter (&$default_values, $context) {
  $default_values['first_name'] = 'deFaulT';
}

```

see also here and How can I set a default value for the country in an addressfield?

---
Tags: 7, forms
---


# Question
Title: What's the difference between combining Rules conditions with AND and just have them follow one after the other?
Is there a difference between using **AND** in Rules Conditions and simply adding Rules Conditions one after the other?

# Answer
> 3 votes
Preface: I'm assuming this question is about D7 ...

### Correction to the prior answer

I'm sorry, but the prior answer is only partially *correct* (which is the same as saying partially *wrong*, n'est-çe pas). Please allow me to briefly correct that (before anybody believes it):

* The question is about (contains) "***... using AND in rules conditions ...***", while the Conditional Rules module cannot be used in Rules *Conditions* (only in Rules Actions). Actually Rules Actions are the reason-to-exist for this (interesting) module.
* If you want to do something more complex, then you can ALSO use ***Rules Components*** as an alternative. So "*You can only do that with conditional rules*" is not true.

### To AND and/or to OR?

Moving on now to the actual question, this is my answer to it:

* This question is a typical Rules newbie question. Since it isn't obvious that within the Rules Conditions there are 3 ways to combine conditions:

+ add an explicit "OR", so that ***either condition*** must be true (for the Rules Actions to be executed).
    + add an explicit "AND", so that ***both conditions*** must be true (for the Rules Actions to be executed).
    + do not add an "OR" or an "AND": that's equivalent to an explicit "AND".
* One might ask then ***`So when do I ever really need to add an "AND"?`*** The answer to that is if you need to more complex logic like in this sample:

Condition 1 **OR** (Condition 2 **AND** Condition 3)

In plain English: the Rules Actions will be triggered if either (or both) of these conditions are true:

+ Condition 1.
    + Condition 2 **AND** Condition 3.

### Rules Conditions inside Rules Actions

**But**, the real Rules fun starts when this (typical) question arises: "*I need to add something like a Rules Condition inside the Rules Actions, how can I do that?*" **( * )**.

To resolve this typical question, there are basically 2 approaches (that I am aware of):

* Use the Conditional Rules module. For an example using the Conditional Rules module (for which there is not a lot of docu available), refer to my answer to the question "How to prevent a node being saved when using the Rules module?".
* Rework the relevant part of your Rules Action(s) into performing a Rules Component. Because in a Rules Component, it is possible to also add Rules Conditions.

Typical scenario: "Use Rules to perform a redirect for users with at least X user points, after some Rules Event Y happened". To get this to work:

+ Create a Rules Component, with number of userpoints as a parameter. Within this Rules Component, add a Rules Condition (there you are!) to check if the parameter is at least X and add a Rules Action to perform the redirect.
    + Create a rule, triggered when Rules Event Y happened. Retrieve the nr of user points for the current user (How to???). And add a Rules Action to invoke the previous Rules Component.

***Sweet, no?***

**( * )**: There are dozens of samples that are variations of this question, my favorite one is when some Rules Action needs to happen based on the number of User Points the current user has (and you do not like to use PHP as a Rules Condition, like I do). If you don't see why that's a variation of it, then first try to find out what the Rules Condition for that would be ... hint: it's a Rules Action, not a Rules Condition.

# Answer
> 3 votes
No difference, except if you want to do something more complex like this:

\____ AND \_____ OR \_____ AND \_____

You can only do that with conditional rules. (If I recall correctly)

---
Tags: rules
---


# Question
Title: CKEditor is adding inline style to resize my textarea on node add/edit form
No matter how many rows I define the textarea to be in the content type configuration, I get a huge editor taking up almost the whole browser window in the node add/edit page. I tracked this down to CKEditor, which is hiding the actual textarea and adding an inline height to the table cell it uses to display the iframe containing the actual field. (Argh.)

Please share any advice on how to make it stop or override it? Since it's inline, I'm not hopeful about using normal CSS.

# Answer
It turns out this is a documented problem in CKEditor. There are some workarounds posted at https://www.drupal.org/node/1154730 but I'd also be intersted in hearing any other ideas.
> 1 votes

---
Tags: entities, wysiwyg, input-formats
---


# Question
Title: How to display multiple multi-value fields inside one for loop?
Here is what I've come up with but it seems I can't do \[key\] to increment along with the body for loop...

```
 {% for key, item in content.body if key|first != '#' %}

{{ item }}

  {{ content.field_text.[key] }}

   {{ content.field_image.[key] }}

{% endfor %}

```

# Answer
> 4 votes
If you use square brackets `[]` in twig, you don't need a period `.`

```
{% for key, item in content.body if key|first != '#' %}

  {{ item }}

  {{ content.field_text[key] }}

  {{ content.field_image[key] }}

{% endfor %}

```

---

A better solution for this might be a field collection or a paragraph, because you depend on that the user is keeping the deltas of the fields in sync.

---
Tags: theming, 8, entities
---


# Question
Title: Rules: Data comparison between saved and unchanged node doesn't work with radio buttons
I successful used the data comparison on rules condition between saved and unchanged node for a date field.

I tried the same with a radio buttons list with two options, but the rule doesn't trigger if I change the value after saving the node.

What's wrong?

Here the rule: http://kopy.io/6GfFi and here is an instream copy of it:

```
{ "rules_last_day_of_work" : {
"LABEL" : "Last Day of Work",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "interval", "rules_conditional" ],
"ON" : { "node_update--job_contract" : { "bundle" : "job_contract" } },
"IF" : [
  { "NOT data_is" : {
      "data" : [ "node-unchanged:field-date-of-last-day-of-work" ],
      "value" : [ "node:field-date-of-last-day-of-work" ]
    }
  },
  { "OR" : [] },
  { "NOT data_is" : {
      "data" : [ "node:field-resignation-layoff" ],
      "value" : [ "node-unchanged:field-resignation-layoff" ]
    }
  }
],
"DO" : [
  { "drupal_message" : { "message" : "test" } },
  { "data_calc" : {
      "USING" : {
        "input_1" : [ "node:field-days-of-notification" ],
        "op" : "*",
        "input_2" : "-1"
      },
      "PROVIDE" : { "result" : { "days_of_notification_negative_sign" : "Days of notification with negative_sign" } }
    }
  },
  { "interval_apply" : {
      "USING" : {
        "interval" : [ "days_of_notification_negative_sign" ],
        "period" : "day",
        "date" : [ "node:field-date-of-last-day-of-work" ]
      },
      "PROVIDE" : { "date" : { "notification_date" : "Notification Date" } }
    }
  },
  { "CONDITIONAL" : [
      {
        "IF" : { "text_matches" : {
            "text" : [ "node:field-resignation-layoff" ],
            "match" : "L",
            "operation" : "starts"
          }
        },
        "DO" : [
          { "data_set" : {
              "data" : [ "node:field-layoff-date" ],
              "value" : [ "notification-date" ]
            }
          },
          { "data_set" : { "data" : [ "node:field-resignation-date" ] } }
        ]
      },
      { "ELSE" : [
          { "data_set" : {
              "data" : [ "node:field-resignation-date" ],
              "value" : [ "notification-date" ]
            }
          },
          { "data_set" : { "data" : [ "node:field-layoff-date" ] } }
        ]
      }
    ]
  },
  { "redirect" : { "url" : "[node:url]" } }
]
}   }

```

THE ANSWER IS: this is the way to put two condition in "OR"

and NOT this one:

# Answer
> 1 votes
### 1st attempt (do some debugging ...)

You clearly have a combination of Rules Conditions and/or Actions which don't seem to react as you expect/want them to do. If I was to get this to work, the first thing I'd do is Rules debugging. Rules is great, but sometimes also tough to debug if things don't work as you'd expect.

There are some typical facilities to do such debugging, but my **K**eep-**I**t-**Super**-**S**imple technique I often use is my ***BINGO***-trick (if you want, you could consider/call it "***adding breakpoints to a rule you want to debug***"). A sample of such rule can be found in my answer to "Which Rules condition can be used to email a user when an admin updates their profile?". Obviously, if you have more then 1 Rules Action (you seem to have (about) 4, following the "Display message *test*"), you may want to make it like Bingo1, Bingo2, Bingo3, etc. Depending on the order they are shown, you also know the order of execution. Stupid, but simple and efficient (I think). Here is an edited version of your rule containing those BingoX-messages (try to import it in your site, note I gave it another machine name):

```
{ "rules_cessazione_with_breakpoints" : {
    "LABEL" : "Cessazione with breakpoints",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "interval", "rules_conditional" ],
    "ON" : { "node_update--rapporto_di_lavoro" : { "bundle" : "rapporto_di_lavoro" } },
    "IF" : [
      { "NOT data_is" : {
          "data" : [ "node-unchanged:field-data-cessazione" ],
          "value" : [ "node:field-data-cessazione" ]
        }
      },
      { "OR" : [] },
      { "NOT data_is" : {
          "data" : [ "node:field-dimissioni-licenziamento" ],
          "value" : [ "node-unchanged:field-dimissioni-licenziamento" ]
        }
      }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "Bingo1" } },
      { "data_calc" : {
          "USING" : {
            "input_1" : [ "node:field-giorni-di-preavviso" ],
            "op" : "*",
            "input_2" : "-1"
          },
          "PROVIDE" : { "result" : { "giorni_neg" : "Giorni neg" } }
        }
      },
      { "drupal_message" : { "message" : "Bingo2" } },
      { "interval_apply" : {
          "USING" : {
            "interval" : [ "giorni-neg" ],
            "period" : "day",
            "date" : [ "node:field-data-cessazione" ]
          },
          "PROVIDE" : { "date" : { "data_preavviso" : "Data Preavviso" } }
        }
      },
      { "drupal_message" : { "message" : "Bingo2" } },
      { "CONDITIONAL" : [
          {
            "IF" : { "text_matches" : {
                "text" : [ "node:field-dimissioni-licenziamento" ],
                "match" : "L",
                "operation" : "starts"
              }
            },
            "DO" : [
              { "drupal_message" : { "message" : "Bingo3a" } },
              { "data_set" : {
                  "data" : [ "node:field-data-licenziamento" ],
                  "value" : [ "data-preavviso" ]
                }
              },
              { "drupal_message" : { "message" : "Bingo3b" } },
              { "data_set" : { "data" : [ "node:field-data-dimissioni" ] } },
              { "drupal_message" : { "message" : "Bingo3c" } }
            ]
          },
          { "ELSE" : [
              { "drupal_message" : { "message" : "Bingo4a" } },
              { "data_set" : {
                  "data" : [ "node:field-data-dimissioni" ],
                  "value" : [ "data-preavviso" ]
                }
              },
              { "drupal_message" : { "message" : "Bingo4b" } },
              { "data_set" : { "data" : [ "node:field-data-licenziamento" ] } },
              { "drupal_message" : { "message" : "Bingo4c" } }
            ]
          }
        ]
      },
      { "drupal_message" : { "message" : "Bingo5" } },
      { "redirect" : { "url" : "[node:url]" } },
      { "drupal_message" : { "message" : "Bingo6" } }
    ]
  }
}

```

I'd be interesting to hear which of those "BingoX" messages will get shown while debugging your rule ... Based on that you should come closer to finding the real reason for your rule which doesn't seem to do what you expect/want.

For more suggestions about Rules debugging, and more advanced facilities, refer to "How can I display the value of a variable inside a condition?"

Note: for those who think "this is not an answer", here is my reply to that already: do you know the story about giving somebody a fish, versus giving a fishline (or whatever that is called)?

### 2nd attempt (why no "entity has field"?)

About your "but the rule doesn't trigger". It may mean that you NOT (repeat: NOT) get that "test" message (as in your very first rules action). If that's the case, I'd wonder (if I was debugging) what results you get if you (temporary) remove the first rules condition? And what if you (temporary) remove the 2nd rules condition?

**Hang on**: you don't seem to have the typical "entity has field" condition (as your very first Rules Condtion). Imagine Rules *thinks* all those field values are blank (because of the missing "entity has field" ...), then neither condition is true (because of the NOT ...), so the rule works as implemented. Therefor, add such "entity has field" Rules Condition, 1 for each of the fields you are already doing those data comparisons. Then let us know the result (the bets are open ...).

---
Tags: 7, rules
---


# Question
Title: How to keep Drupal site code in version control in sync with production code when using drush updates on servers?
I have 50 D7 sites I support (none are multisite). We do local development for changes to themes and modules tied to new functionality and bug fixes. Once the update works locally, we check that into git and use automation to push changes to our test servers.

Security and core updates tend to be run directly on our test and production sites using drush upc --security-only

How can I keep our git repo in sync with the state of production code?

I can request a dump of production code and use a difftool to compare that to the latest commit and then apply those updates to the git repo code and commit, but is there a better way to do this?

# Answer
You really have two options:

1. Assuming you are deploying code to your test server by cloning your code base from a service like github then you can always go in the reverse direction for security patches. You can patch your test servers (or even Prod, though thats not recommended) directly, commit the patched changes to your local git repo on your test server and then push that commit to your remote repo on github. On your local development server you can now pull from your remote git repo on github and everything is in sync.
2. Alternatively (and probably less optimal) you can patch your code on your test server directly AND you can simultaneously apply the same patch to your local code base. This way the same changes should be made in both places. This method is DEFINITLY not as good because it makes A LOT of assumptions about how well you are keeping everything in sync, but it can work.
> 1 votes

---
Tags: 7, drush, deployment, version-control
---


# Question
Title: How to view a user's personal data after the user performs a login?
I wonder how to view a user's personal data after the user performs a login.

Example: they have 4 tables in database "it", "business", "hrm", "educ". All the 4 tables have a student data when the 1st column in it table are login only the first column in table are viewed his data in webpage.

# Answer
> 0 votes
You might be able to use the Forena module (disclosure: I'm a co-maintainer) to build custom queries to retrieve the data directly from such **database** (of which its format can be MS SQL, MySql, Oracle, some PDO compliant database, etc). Think of those custom queries as standard SQL statements that fit your requirements (to retrieve the data). And combine this with the creation of some custom reports.

Those reports can then be shown in an appropriate page (with a specific path), or you could show them in a block, by using Forena's integration with the BEAN module.

PS: I'm assuming this question is about D7.

---
Tags: users, database
---


# Question
Title: Math Field doesnt recalculate when fields are populated
I have 2 Select list(Integer) fields and I am using Math Field to get the sum of the two fields. But when I populate the first value the field is calculated and when I populate the second field it does not recalculate. Help me please.

# Answer
The (fairly new) Math Field module for D7 is a not commonly known/used alternative to Computed Field).

However, there are still a few other (known) issues with it, as mentioned also on its project page:

1. The cTools math expression library causes an error when using function that take more than one parameter. This effects pow(), min(), max() (#1958538: Improve math expression engine).
2. Math Field does not yet support multivalue options fields (checkboxes, or multiselect) (#2483453: Add aggregate functions for multivalue fields).

However, if you're trying to use this module to handle multivalue fields, then that would explain why you can't get that to work (as per the issue mentioned before: multi value fields are not yet supported).
> 1 votes

---
Tags: entities, javascript
---


# Question
Title: How do I see the value of one field of a multi-item field in views formatter
I have a custom views formatter.

```
function template_preprocess_views_view_flot_views_time(&$variables) {
  $view = $variables['view'];
  $field_name = 'foo_bar';
  foreach ($view->result as $row) {
    $field_value = $view->field[$field_name]->getValue($row);
  }
}

```

This works when the field is a single-value field. However, I have a couple multi-value fields. The result of the above expression is always "1" for these fields. These fields can be identified because

```
 $view->field[$field_name]->multiple == TRUE

```

I can use

```
kint($view->field[$field_name]->getItems($row));

```

to see that this is an array with a render array and raw data. The value as a string can be found at:

```
$view->field[$field_name]->getItems($row)[0]['rendered'][#markup']

```

If the multi-value field is named foo, and has three parts, 'bar', 'baz', and 'qux', is there a better way to get the value of foo\_bar or foo\_baz?

I've been looking at the documentation for core/modules/views/src/Plugin/views/field/Field.php but it's not helping.

# Answer
> 2 votes
You don't need to search for another method, `Field::getValue()` returns the array you are looking for:

```
if ($view->field[$field_name]->multiple) {
  $field_array = $view->field[$field_name]->getValue($row);
}

```

I don't know if there is a documentation, but you can see this in code:

https://api.drupal.org/api/drupal/core!modules!views!src!Plugin!views!field!Field.php/function/Field%3A%3AgetValue/8.2.x

**Difference between field values from view result and entity**

If you have a *standard* multivalue field like text or number in a view and don't change any options, `getValue($row)` returns a one-dimensional array with the values from the main property of the field. If not you have somehow configured the view so that it shows a different result.

You can although get the original entity field data, which is independent from the configuration of the view. For this the field needs to be in the row entity:

```
$field_array = $row->_entity->{$field_name}->getValue();

```

This is then a two-dimensional array with multiple values and multiple properties.

---
Tags: views, 8
---


# Question
Title: How would a customer be able to get free shipping when there are no free shipping options?
We just launched our ecommerce store using Drupal Commerce Kickstart, which heavily uses Rules to manage shipping.

We have had two orders from the same Virginia-based customer. Both orders were processed without shipping applied. When I select the same items, enter the same Virginia USA shipping address and go through the checkout process, I get the expected behavior of Standard Shipping - $15 being applied. I cannot replicate the behavior.

The checkout process / sequence is as follows.

The "Standard Shipping - Domestic" rule is called for:

1. Addresses within the "US"
2. Orders not contain three Product Categories (bikes, wheels, forks)

\*The order in question does not contain these items.

I attempted to duplicate in both Chrome Incognito & Firefox. No issues on my side. I see the following:

1. One option to select from under "Shipping"
2. Shipping applied under "Review Order"
3. When viewing in admin mode, I see shipping applied as a line item on the order.  PLUS - The correct sequence is maintained

When I view the customer order, there is no shipping line item.

AND the customer appears to be going through a different order sequence and bypasses the Shipping selection. How is this possible? I am totally confused.

How is it possible to bypass the checkout sequence in Commerce Kickstart? 1. Test: Checkout \> Shipping \> Review Order 2. User: Create order \> Add item to cart \> Pending (Which is typically after the order is fully paid. We have confirmed that payment has been received.)

Very curious. Curiouser & curiouser.

# Answer
> 0 votes
If the issue is that shipping selection needs to happen for Express Checkout users, then if you edit the Express Checkout module's order confirmation checkout pane you can choose which checkout panes from other pages should appear on the final confirmation page. Make sure you check the box there for shipping service selection and it should show up as expected.

---
Tags: commerce, rules
---


# Question
Title: Drush is not recognizing Acquia extension
I am using Acquia and Drush 8.1.8. I am following Acquia's instructions to load Drush extensions and aliases. My `~/.drush` directory looks like this:

```
nickheiner@Nicks-MacBook-Pro.local:~/.drush  λ ls -l ~/.drush/
total 176
-rw-------@ 1 nickheiner  staff  43320 Feb  9 13:25 acapi.drush.php
drwxr-xr-x  6 nickheiner  staff    204 Feb  9 13:26 cache
-rw-------@ 1 nickheiner  staff   6026 Feb  9 13:14 cloudapi.acquia.com.pem
-rw-r--r--  1 nickheiner  staff   7741 Dec 19 16:52 drush.bashrc
-rw-r--r--  1 nickheiner  staff   1937 Dec 19 16:52 drush.complete.sh
-rw-r--r--  1 nickheiner  staff   2811 Dec 19 16:52 drush.prompt.sh
-rw-r--r--  1 nickheiner  staff  13628 Feb  9 13:19 drushrc.php
-rw-------@ 1 nickheiner  staff   1416 Feb  9 13:14 preview1.aliases.drushrc.php

```

However, Drush is not recognizing the commands:

```
λ ./drush cache-clear drush
'drush' cache was cleared.                                                [success]

λ ./drush help --filter=acapi
The specified command category acapi does not exist.                      [error]

```

I am also not seeing the alias:

```
λ ./drush sa
@none
@self
default

```

I tried opening up the permissions so they look like the following, but it did not solve the problem:

```
λ ls -la ~/.drush
total 176
drwxrwxrwx  10 nickheiner  staff    340 Feb 10 10:36 .
drwxr-xr-x+ 57 nickheiner  staff   1938 Feb 10 11:04 ..
-rwxrwxrwx@  1 nickheiner  staff  43320 Feb  9 13:12 acapi.drush.inc
drwxrwxrwx   6 nickheiner  staff    204 Feb  9 13:26 cache
-rwxrwxrwx@  1 nickheiner  staff   6026 Feb  9 13:12 cloudapi.acquia.com.pem
-rwxrwxrwx   1 nickheiner  staff   7741 Dec 19 16:52 drush.bashrc
-rwxrwxrwx   1 nickheiner  staff   1937 Dec 19 16:52 drush.complete.sh
-rwxrwxrwx   1 nickheiner  staff   2811 Dec 19 16:52 drush.prompt.sh
-rwxrwxrwx   1 nickheiner  staff  13628 Feb  9 13:19 drushrc.php
-rwxrwxrwx@  1 nickheiner  staff   1416 Feb  9 13:12 preview1.aliases.drushrc.php

```

What am I doing wrong?

# Answer
> 0 votes
Can you confirm that you can see your acquia site aliases?

```
drush sa

```

I haven't done anything beyond the suggested `tar -C $HOME -xf $HOME/Downloads/acquiacloud.tar.gz` and `drush help --filter=acapi` shows all the commands.

---
Tags: drush
---


title: Display date and time in header

text:
# Question
Title: Display date and time in header
I would like to display current date and time to the header section.

I am using a subtheme of Bartik. Any suggestions?

# Answer
> 5 votes
You can also add code `page.html.twig` as well.

For print only date use `{{ "now"|date("m/d/Y") }}`

More Details

http://twig.sensiolabs.org/doc/2.x/filters/date.html

https://stackoverflow.com/questions/17364206/symfony2-how-can-i-set-twig-dated-f-y-filter-to-output-months-in-swedish

# Answer
> 2 votes
I can't comment directly on Smalution's answer, but can confirm that

`{{ "now"|date("m/d/Y") }}`

in twig DOES respect drupal user timezones. (Tested it in america/new york - 2:50, switched to america/edmonton - 12:50) as per mpdonadio's question.

# Answer
> -1 votes
For this you can create custom block and insert the PHP date function in it. (Install PHP module for insert php code in block or drupal site). Place this block on the header or where you want to place.

---
Tags: 8, datetime
---


# Question
Title: What's the purpose of the type "block_settings" in schema.yml files?
In the block\_example module, from the Drupal 8 Examples for Developers, what purpose does the file block\_example.schema.yml serve?

I'm familiar with using schema.yml files to set configuration and access it like so:

```
$config = \Drupal::config('system.maintenance');

```

However, it appears that the "block\_settings" type is different.

# Answer
> 5 votes
That's basically config schema inheritance, like you have class inheritance in PHP.

*Any* type that you define can be used as by by someone else. And it is what you want to do when you extend the class (usually a plugin) for which it is defined.

block\_settings itself is a type that extends from mapping and defines a few common keys, it is defined in core.data\_types.schema.yml

```
block_settings:
  type: mapping
  label: 'Block settings'
  mapping:
    id:
      type: string
      label: 'ID'
    ...

```

(Multiple keys in there shouldn't exit and are for example block\_content specific, but that's a bit complicated to fix now).

And if you'd provide a block plugin that would extend from example\_configurable\_text, then you can define it like this:

```
block.settings.my_block:
  type: block.settings.example_configurable_text
  mapping:
    another_thing:
      type: text
      label: 'Another thing'

```

And you automatically get everything it defines, and what it itself inherits from block\_settings.

---
Tags: 8
---


# Question
Title: Dynamically display view block based on based on different view filters
I have a view as a page layout. That view allows the user to choose from a list of tags to filter content.

What I'm trying to do is - when someone selects one of the tags to filter content, a separate view block is displayed, based on the tag they select from the filter list.

Is there a way to do this?

# Answer
We did something similar on our site -- on the left hand side we had a list of lesson plans, and when you clicked one, it used AJAX to dynamically update the lesson pane on the right. Sounds basically like what you want.

Here's the set up:

Make a view with both a block and a page, and configure the block so that the two show up on the same page. (example.com/my-view should show the block on the left side and the page on the right side.)

In the block body, he put the list of lessons alongside the following code in `<script>` tags:

```
$('.lesson').on('click', function(e) {
   e.preventDefault();
   // loads lesson into the content part of the page
   var contextualFilter = $(this).text(); // get the lesson title from the selection
   var AJAXPromise = AJAXLesson(contextualFilter); // get lesson from server and load into the content part of the page
   AJAXPromise.done(function() {
      // make promise, waiting for ajax call to return before changing URL and sending analytics page view
      window.history.pushState(contextualFilter, "", "http://example.com/my-view/" + SpaceEncodeString(contextualFilter)); // change URL to requested lesson with dashes instead of spaces
   })
});

```

Where `AJAXLesson()` is a function that returns a `$.ajax({ ... });` object with the lesson plan data.

```
function AJAXLesson(lessonName) {
   // loads lesson from server
   return $.ajax({
      url: 'http://example.com/views/ajax',
      type: 'post',
      data: {
         view_name: 'myview',
         view_display_id: 'lessons', // this'll be different for you
         view_args: SpaceEncodeString(lessonName), // removes spaces and replaces with dashes
      },
      dataType: 'json',
      success: function(response) {
         if (response[1] !== undefined) {
            document.title = lessonName; // change page title
            $('#block-system-main').html(response[1].data); // CRITICAL: paste lesson in content
         }
      }
   });
}

```

Your code will look different, but that's the basic concept anyway.
> 1 votes

---
Tags: 7, views
---


title: Create an XML page by a custom module

text:
# Question
Title: Create an XML page by a custom module
I need to create an XML page. I created a page with my custom module, and I tried to display it, but it showed as a normal Drupal page with blocks.

```
function my_custom_function_name_xml_list() {
  $output = '<?xml version="1.0" encoding="UTF-8">';

  return $output;
}

```

How do I avoid Drupal adds its own content to the output of my function?

# Answer
> 6 votes
Instead of returning the string you want to use as output, print it using code similar to the following one.

```
print $output;
module_invoke_all('exit');
exit();

```

`$output` is the variable containing the output you want to show.
While the `module_invoke_all('exit')` call is not strictly necessary, it notifies other modules that Drupal is terminating. There are modules that implement hook\_exit() to do their job, and they will not work, without that call; their purpose is to write something in a Drupal variable, or in a database table, and they don't interfere with the output your are producing.

The reason why it is necessary to do this is the code used by index.php, which contains the following:

```
$return = menu_execute_active_handler();

// Menu status constants are integers; page content is a string.
if (is_int($return)) {
  switch ($return) {
    case MENU_NOT_FOUND:
      drupal_not_found();
      break;
    case MENU_ACCESS_DENIED:
      drupal_access_denied();
      break;
    case MENU_SITE_OFFLINE:
      drupal_site_offline();
      break;
  }
}
elseif (isset($return)) {
  // Print any value (including an empty string) except NULL or undefined:
  print theme('page', $return);
}

drupal_page_footer();

```

If you return a string, it is passed to `theme('page')`, which renders the page as you are noticing; if you return nothing, then both `is_int($return)` and `isset($return)` are `FALSE`, and the relative code is not executed.

The equivalent for Drupal 7 for the code I wrote for Drupal 6 would be the following one:

```
print $output;
drupal_exit();

```

drupal\_exit() contains already the call to `module_invoke_all('exit')`.

# Answer
> 2 votes
Basically all you need is `hook_menu()` and `node_feed()` to create a basic RSS feed matching the RSS 2.0 Specification.

`node_feed()` then ensures by calling `drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8')` the correct headers getting applied and only RSS markup getting rendered.

### But if you want a really, really custom XML feed ...

... you have to write your own `node_feed()` function and further on your own `format_rss_channel()` and `format_rss_item()` functions. I simply pasted these three functions into a custom module, renamed them, and customized them for my own needs. Here's a simplified example:

```
/**
 * Implements hook_menu().
 */
function MYMODULE_menu() {

  $items = [];

  $items['custom.xml'] = [
    'page callback'   => '_custom_feed_page_callback',
    'access callback' => TRUE,
    'type'            => MENU_CALLBACK,
  ];

  return $items;
}

/**
 * Return feed for indicated content.
 */
function _custom_feed_page_callback() {

  $nids = db_select('node', 'n');
  $nids->fields('n', ['nid', 'created']);
  $nids->condition('n.status', 1);
  $nids->orderBy('n.created', 'DESC');
  $nids->range(0, 10);
  $nids = $nids->execute()->fetchCol();

  _custom_xml_node_feed($nids);
}

/**
 * Generates and prints a custom XML feed.
 */
function _custom_xml_node_feed($nids) {

  $nodes = node_load_multiple($nids);
  $items = '';
  foreach ($nodes as $node) {

    $node->link = url("node/$node->nid", ['absolute' => TRUE]);

    $items .= _custom_xml_format_rss_item($node->title, $node->link);
  }

  global $base_url;

  $channel_defaults = array(
    'title' => variable_get('site_name', 'Drupal'),
    'link' => $base_url,
  );

  $output = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\" ?>\n";
  $output .= "<!DOCTYPE CUSTOM.EVENTS SYSTEM \"custom_import.dtd\">\n";
  $output .= "<CUSTOM.EVENTS version=\"2.25\">\n";
  $output .= _custom_xml_format_rss_channel($channel_defaults['title'], $channel_defaults['link'], $items);

  drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
  print $output;
}

/**
 * Formats an XML channel.
 */
function _custom_xml_format_rss_channel($title, $link, $items) {

  $output = "  <EVENTLIST>\n";
  $output .= "    <SOURCE id=\"12345\">\n";
  $output .= '      <TITLE>' . check_plain($title) . "</TITLE>\n";
  $output .= '      <LINK>' . check_url($link) . "</LINK>\n";
  $output .= "    </SOURCE>\n\n";

  $output .= $items;
  $output .= "  </EVENTLIST>\n";
  $output .= "</CUSTOM.EVENTS>\n";

  return $output;
}

/**
 * Formats a single XML item.
 */
function _custom_xml_format_rss_item($title, $link) {

  $output = "    <EVENT>\n";
  $output .= '      <TITLE>' . check_plain($title) . "</TITLE>\n";
  $output .= '      <LINK>' . check_url($link) . "</LINK>\n";
  $output .= "    </EVENT>\n\n";

  return $output;
}

```

---

Credits: I got the idea to do it that way after reading this brilliant blog post https://www.phase2technology.com/blog/creating-rss-feeds-with-a-light-hand

Parked working example module on GitHub https://github.com/leymannx/custom\_feed

---
Tags: hooks
---


# Question
Title: Migrate Drupal locator content to Wordpress site
I use the migrate module to populate locator data to other Drupal sites. We have a main site that allows members to update their locations. Each location can also be flagged so that if its checked as an "A" location, when Cron runs it populates on the "A" site and the same for the "B" site. This keeps the content updated on the other sites when any changes are made and allows us to only have to update on one site. All the sites are running on Drupal 7.

Now if we added a WordPress site and wanted to route the "A" locations content to that site instead, can this be done the same way?

Thanks!

# Answer
also saw your email...

The migrate module is very Drupal-centric. It runs on a Drupal site, and the primary (99.99%) use-case is to pull data into that Drupal site - all destination plugins I know of write to the local Drupal database. That being said, it would be entirely possible to write a destination plugin that pushed to an external destination - like, say, a WordPress database or a web service for creating content.

Personally, my only experience with WordPress is in importing content from WordPress exports (XML files) into Drupal, so I don't know how challenging pushing content to WordPress would be.
> 0 votes

---
Tags: migrations
---


title: JavaScript files not loading

text:
# Question
Title: JavaScript files not loading
The JavaScript files for my theme aren't loading. What am I missing?

My theme.info.yml:

```
name: theme
type: theme
description: Custom theme.
core: 8.x
base theme: classy
version: 8.x-1.0
libraries:
  - theme/global-styling
#stylesheets-remove:
#  - '@classy/css/components/tabs.css'
#  - core/assets/vendor/normalize-css/normalize.css
regions:
  logo: 'Logo'
  navigation: 'Navigation'
  slider: 'Slider'
  content: Content  # the content region is required
  contact: 'Contact (Content Top)'
  testimonials: 'Testimonials'
  call-to-action: 'Call To Action'
  footer_logo: 'Footer logo'
  footer_first: 'Footer first'
  footer_second: 'Footer second'
  footer_third: 'Footer third'
  footer_copyright: 'Footer Copyright'
regions_hidden:
  - sidebar_first

```

My theme.libraries.yml:

```
global-styling:
  version: 1.x
  css:
    theme:
      css/animate.css: {}
      css/bootstrap.css: {}
      css/et-line-icons.css: {}
      css/font-awesome.min.css: {}
      css/extralayers.css: {}
      css/settings.css: {}
      css/magnific-popup.css: {}
      css/owl.carousel.css: {}
      css/owl.transitions.css: {}
      css/full-slider.css: {}
      css/text-effect.css: {}
      css/menu-hamburger.css: {}
      css/style.css: {}
      css/responsive.css: {}
      css/custom.css: {}
      //vjs.zencdn.net/5.8.8/video-js.css: { type: external }
  js:
    //vjs.zencdn.net/ie8/1.1.2/videojs-ie8.min.js: { type: external, minified: true }
    js/modernizr.js: {}
    js/bootstrap.js: {}
    js/bootstrap-hover-dropdown.js: {}
    js/jquery.easing.1.3.js: {}
    js/skrollr.min.js: {}
    js/smooth-scroll.js: {}
    js/jquery.appear.js: {}
    js/wow.min.js: {}
    js/page-scroll.js: {}
    js/jquery.easypiechart.js: {}
    js/jquery.parallax-1.1.3.js: {}
    js/jquery.isotope.min.js: {}
    js/owl.carousel.min.js: {}
    js/jquery.magnific-popup.min.js: {}
    js/popup-gallery.js: {}
    js/text-effect.js: {}
    js/jquery.tools.min.js: {}
    js/jquery.revolution.js: {}
    js/counter.js: {}
    js/jquery.countTo.js: {}
    js/jquery.fitvids.js: {}
    js/imagesloaded.pkgd.min.js: {}
    js/classie.js: {}
    js/hamburger-menu.js: {}
    js/main.js: {}
  dependencies:
    - core/jquery
    - core/drupal
    - core/drupalSettings

```

# Answer
Try this : Add this code in .info.yml

```
libraries:
        - 'theme/global-styling'
        - 'theme/global-scripting'

```

And include the CSS and JS the libraries.yml file like below.Include styles and scripts seprately.

```
 global-styling:
    css:
      theme:
       css/style.css: {}

 global-scripting:
    css:
      theme:
         js/script.js: {}

```
> -1 votes

---
Tags: 8, javascript, .info
---


# Question
Title: Field type Entity Reference as select list but based on value
I want field with entity reference showed as select but based on value from the another field in the same form \[radio button field\] for example the entity reference field will list these values

-entity 1
-entity 2
-entity 3
-entity 4

and the field radio button will hold countries like so:

-England
-Germany

notice that the entities reference (Content Type) has field called country, so when i check the value "England" i want the field entity to be filtered based on England for ex: -entity 1 & -entity 4 and same if i clicked Germany.

is that applicable in Drupal 7 even by Views module, or i have to do it custom !?

# Answer
You can use Dynamic dependent fields module.

Project page says:

> Makes field value or options depend on other field values when editing entity.
> 1 votes

# Answer
i think it is done by Conditional Fields see tutorial here
> 1 votes

---
Tags: views, entities
---


# Question
Title: Hide a field on a user profile if the logged in user has a specific role
I have many fields added for users. What I want is the following: If the logged in user has a role W and is viewing a user page that belongs to a user of role X then show field Y. Otherwise, field Y should not be visible.

I have tried using a a module named "Field Formatter Conditions" that supposedly has rules integrations and offers the Event: A field is being rendered and the Action: Hide a field. However, when I select the action to hide the field, There is nothing to be configured and I just get the save button.

Kindly suggest how I can accomplish the target and I prefer if the solution is based on rules.

# Answer
> 1 votes
You can use the Field Permissions as Pierre's answer said. You just need to change the role that can see that field.

In the page listing all the installed modules, click on *Configure* link shown for the *Field Permissions* module.

>

The next page will show all the fields added to entities, their type, the entity to which they are added, the bundles for that entity which have that field, and a summary of the permissions for that field.
For the field that you want to change the permissions, click on the entity containing it, which is a link to another page. In your case, that link is labelled *User*, since the field is for the *User* entity.

>

The link will take you to a form where you can change its permissions.
On *Field visibility and permissions* click on *Custom permissions*. On the *View anyone's value for field Y* row, select only the checkboxes for the *admin* and *W* roles.

>

In this way, the field will be visible to the users with those roles, when they watch the account of other users.

# Answer
> 0 votes
I think you would come closer to an actual solution by using the Field Permissions module.

> ... allows site administrators to set field-level permissions to edit, view and create fields on any entity.

Not sure if it'd cover all your requirements, but it might be part of the solution to your puzzle. For sure you can use it to "*Hide a field on a user profile if the logged in user has a specific role*" (as in the title of your question).

> If the logged in user has a role W and is viewing a user page that belongs to a user of role X then show field Y. Otherwise, field Y should not be visible.

That sounds like using Field Permissions to configure your field Y so that this field is **shown** to users with role W and **hidden** to users without role W. This probably does not take into account "*... a user page that belongs to a user of role X...*".

---
Tags: entities, rules, users
---


# Question
Title: Views Configure contextual filter by user's country
Drupal 7, commerce kickstart2.

Need to create a view with ContentType ProductDisplay. ProductDisplay has field Product. A Product has multiple field of a Country type.

User object has a property Country filed by IP2Country Module. The view need to show only products with user’s country.

View: type=page, link= /products (no other arguments in url expected), added releation Product

Here what I tried

1. Created Contextual filter: "*Product: Country List (indexed)*". Had to add index to this field so it can be select in contextual filter
2. Configured default argument for the "*When the filter value is NOT in the URL*". By using "hook\_views\_plugins" created "*Current user's Country name*" argument type. It is working and providing correct argument value - user’s country

Didn’t manage to make it work. Also, tried some other things and spent few hours browsing web for a possible solution. Didn't find any similar problems or solution. There’re many examples with taxonomy terms and url args.

As a plan B, think to create view for every country and override main view, but don't like it

Is a better solution to the task possible?

Thanks!

# Answer
Found the problem!

All I did was correct, except one thing; I choose wrong View type during creation.

wrong: selected Show "*Product display*"

working: choose Show "*Content*" of type "*Product display*"

Don't know the difference, but it's working
> 0 votes

---
Tags: commerce
---


# Question
Title: Blocks disappeared when I changed themes
Some blocks are no longer showing under Block Layout (or under custom blocks). Some of the blocks came from views. And the views are still there and in block mode. Another block was of the type "Contact Block".

why does my views-block not appear? And why did the contact block disappear?

All I did was change the default theme to a standard theme. Then I uninstalled the previous theme and removed all its files. Then I put in a new theme and activated it and set it as default.

# Answer
Just click `Place block` and in the filter up top, search for them and place them again.
> 4 votes

# Answer
Seems like the block placement is in context of theme. If you see the exported block configuration file, you will see theme as dependency which kind of ensures the block configuration will work in context of theme it was configured in.

As a solution yes you have to configure the block for each theme separately.
> 1 votes

# Answer
You need to check **Demonstrate block regions** of both the theme.

Some regions may exist on first and not present in second theme. You need to reconfigure that blocks.
> 0 votes

---
Tags: 8, blocks
---


# Question
Title: Create dynamic external link URL without filtering or stripping protocol
In my module I'm creating a dynamic external link to launch a local FileMaker database client and run a FileMaker script that finds a record like so:

```
FMP://192.168.123.123/DatabaseName.fmp12?script=FindRecord&RecordID=12345

```

The problem is no matter whether I use the Drupal 7 link `l()` function with attribute array `absolute = true` or `external = true` or if I assemble the link markup myself, either the anchor's href attribute gets stripped entirely or the protocol of `FMP` gets replaced with `HTTP`.

What do I need to do to let Drupal know this URL is safe to be outputted unmolested in outgoing emails?

# Answer
> 0 votes
I realised it's not Drupal changing the URL but GMail that doesn't like the protocol.

So I created a simple PHP redirect script and link from my Drupal module to that instead e.g.

```
<?php

header("Location: FMP://192.168.123.123/DatabaseName.fmp12?" . $_SERVER['QUERY_STRING']);
exit;

?>

```

---
Tags: navigation, input-formats, emails
---


# Question
Title: Second ajax button not working on user profile form
I have added a custom button which has an ajax callback with the following code to the user profile form.

```
$form['validate_2'] = array(
          '#type' => 'button',
          '#value' => t('validate 2'),
          '#ajax' => array(
            'callback' => 'example_validate',
            'wrapper' => 'validate-settings',
            'method' => 'replace'
          ),
          '#name' => 'user_validate_2',
          '#id' => 'user-validate-2',
          '#weight' => 10
        );

```

But when I click on it, it gives me ajax error in popup saying

```
An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /system/ajax
StatusText: n/a
ResponseText:
( ! ) Fatal error: Call to undefined function user_profile_form_validate() in /includes/form.inc on line 1520

```

In my ajax callback I'm simply displaying the `$form_state` array. Any idea what I'm doing wrong?

The form's own submit button is not with ajax.

```
function example_validate($form, &$form_state) {
dsm($form_state);
}

```

# Answer
If Drupal can't find one of its core files it's nearly always because you're trying to use it in a context in which it wouldn't be automatically included.

For example when you use the user profile form normally, the menu item makes sure the file containing the form functions is included.

For your example the missing function is in user.pages.inc, so:

```
form_load_include($form_state, 'inc', 'user', 'user.pages');

```
> 1 votes

---
Tags: 7, forms, ajax
---


# Question
Title: hook_commerce_order_presave firing on page load
I'm trying to run some code whenever an order is updated. I've found the function hook\_commerce\_order\_presave which fulfils this purpose, but it seems this also fires on page load. Is this normal, or is there another module that would be causing this? Is there a more suitable function I could use?

# Answer
> 0 votes
This is unusual. The *hook* should not be executed on every page load. You might want to check if some code in a custom module, custom theme, rule is causing an update of *commerce\_order* which could trigger the hook.

To ensure that the order is updated on every page load, you can implement `hook_entity_update()`, in your custom module

```
function MODULE_entity_update($entity, $type) {
  if ($type == 'commerce_order') {
    // Execute your code here.
  }
}

```

If the code inside `if` loop is still executed, you can be sure that the *something* is triggering update of commerce order on each page load. And you can proceed to find out what is the actual cause of the problem.

---
Tags: 7, commerce
---


# Question
Title: Views Path Settings is not redirecting to particular path?
I have been working on drupal 7.54 version.

I have created on sample view and trying to display the view in particular path.

Here, I have mentioned the path as comment-count, but its not getting redirected to the path, because its taking as query string.

How can I change this thing.

Is there any problem in latest instance or else guide me how to sort out this problem?

# Answer
> 1 votes
Go to /admin/config/search/clean-urls and enable the clean urls.

Then try these steps If clean Url test is failed. enable mod\_rewrite apache from httpd.conf

1. open httpd.conf
2. find mod\_rewrite
3. just remove # to enable
4. once it enable then you can run Clean URL
5. this will show check box tick on it and save it

---
Tags: 7, views
---


# Question
Title: How to insert drupal username and email fields into create booking form?
Am using the Booking Time slot module. The module introduces a "Booking entity".

I want to insert the default drupal 'username' and 'email' fields into the form used in creating a new booking, so that user is able to register while completing form.

Assuming "Booking" was a "Content Type", I would use the inline registration module. However, that option does not exist in this case.

Is there a way to insert the fields or merge the 2 forms?

# Answer
> 0 votes
To create a new booking, the form for that already contains a (required) entity reference field to an existing user (with `field_bt_user`). Head over of `admin/structure/booking/fields` in your own site to get more details on that.

If you however want to add another ***username*** and ***email*** field, just use "Add new field" on `admin/structure/booking/fields` for both of those fields.

However, as per your "*... so that the user is able to register while completing form ...*" (as contained in your question), it appears to me that you want an anonymous user to be able to do so. If that's the case, you'll have to decide about how an anonymous user should complete that form, for the ***required*** field `field_bt_user`. You might think "*just make that field no longer required*", but I doubt that's a good idea to do, since there must be good reason for this module why that field is required.

Because of what is above, I think you should slightly adapt your workflow regarding that "*... so that the user is able to register while completing form ...*":

* Step 1: use the Rules module to intercept a path equal to `/admin/structure/booking/add`, if it is entered by an anonymous user, and redirect them to the login page, with an option to register and a Drupal message shown to them like "this path can only be used by authenticated users, try again after login" (piece of cake with Rules).
* Step 2: wait for the login to be completed, and have the authenticated user enter the same path (`/admin/structure/booking/add`) again. When that happens, the Rules Actions in custom rule as in Step 1 will not be executed anymore (since user is authenticated), while the form is not used by an already registered user.

***If you can't solve a problem,***

***then prevent the problem from ever happening again is a typical plan-b ...***

---
Tags: users, bookings
---


# Question
Title: Drupal 8 Contextual Filter Exclude option
I have a case where I want to list all taxonomy terms but exclude the term that is filled in the url. In D7, in contextual filters you could expand 'More' and check that option. I cannot find this option in D8. Am I looking in the wrong place or just not seeing it, or is this option not (yet) in Drupal 8.

If the latter, is there any other option to become this? I searched around but without any succes.

Thanks in advance

# Answer
> 0 votes
I ran into the same problem, and I got it working because in D8 I didnt have Search API installed(still beta in D8 at time of this post). Not sure if you have this extension installed.

Also I had to enable Search API term handlers. Then you should be able to see the Exclude option in the Views contextual filters.

# Answer
> 0 votes
It can also simply be a visibility issue in the D8 GUI, try collapsing the other sections and/or zoom out in your browser.

---
Tags: 8, views
---


# Question
Title: Add ctools processing for content loaded via ajax
I have a search result page where all the searched results are loaded using ajax call. For each result, there is a button which should open a form in the modal.

The code snippet which is loading a button on the search result is as follows:

```
$build[$entity->id]['footer']['footer-bottom-section']['view-modal-form'] = array(
        '#type' => 'markup',
        '#markup' => l('<span class="glyphicon glyphicon-ok"></span> Get Best Price', 'request/add/'.$space_id.'/'.$entity->id, array('html'=>TRUE,'attributes'=> array('class'=>array('btn','btn-orange', 'pull-right', 'ctools-use-modal')))),
    );

```

The button is loaded properly on each search result, and it has all the classes provided. But it does not have `ctools-use-modal-processed` class.

I know the reason since the page is already loaded and results are added to the page through ajax after load finishes, ctools is not finding `ctools-use-modal` class to process.

I would like to know, how can I trigger ctools to process my ajax loaded search results so that it can add modal form for each searched result?

**EDIT:** Following is the js function which is calls a custom menu callback function, to load results:

```
function fetchNext(url, $parent) {
    $parent.append('<div id="space-loading"><span class="glyphicon glyphicon-refresh loading-spin" aria-hidden="true"></span>Loading</div>');
    $.get( url, function( data ) {
        $parent.append( data );
        $('.load-next').bind('inview', function (event, visible) {
            if (visible && !($(this).hasClass('disabled'))) {
                var url = $(this).attr('href');
                fetchNext(url, $(this).parent());
                $(this).remove();
              }
            });
        $('.load-next').click(function (event) {
            event.preventDefault();
            var url = $(this).attr('href');
            fetchNext(url, $(this).parent());
            $(this).remove();
        });
        processAfterLoad();
    }).fail(function() {
        $('#space-loading').text('Error in loading spaces. Please refresh page');
    });
}

```

This is line which calls above function:

```
$('.load-next').bind('inview', function (event, visible) {
            if (visible && !($(this).hasClass('disabled'))) {
                var url = $(this).attr('href');
                fetchNext(url, $(this).parent());
                $(this).remove();
              }
            });

```

Following is the kind of URL which will be called:

```
/lazyspaces/<Google places api locality>?<lat, lng, geolocation, sort, page>

```

for e.g.:

```
/lazyspaces/Thane-West--Thane--Maharashtra--India?lat=19.2444738&lng=72.9814877&geolocation=Thane%20West%2C%20Thane%2C%20Maharashtra%2C%20India&sort=distance&page=2&plain=1&lastdistance=8.80

```

**Menu callback:**

```
$items['lazyspaces'] = array(
        'title' => 'Find a Space',
        'page callback' => 'discover_lazy_spaces',
        'access callback' => 'entity_access',
        'access arguments' => array('view', 'space', 1),
        'file' => 'includes/search.utils.inc',
);

```

Here `discover_lazy_spaces` function, extracts get parameters and send it to a query to fetch results from database and then builds result list.

# Answer
> 1 votes
You need to call `Drupal.attachBehaviors()` after inserting the new content into the page.

Change this:

```
$parent.append( data );

```

To this:

```
$parent.append( data );
Drupal.attachBehaviors($parent);

```

---
Tags: 7, theming, forms, ajax, chaos-tool-suite
---


title: How do we re-use Paragraph items?

text:
# Question
Title: How do we re-use Paragraph items?
Paragraph items are only available to their parent entities. But is there any known way to make it possible to re-use existing Paragraph items?

# Answer
> 13 votes
Paragraphs is focused on reusing layouts not content. The most obvious implication is on revisions.

In a standard reference field you reference the latest revision of the target. When you roll back the parent the target keeps the actual content. Paragraphs on the other hand keeps track of the revisions and allows you to rollback an entity including the content of the paragraphs that are owned by the entity. And that's the problem, if Paragraphs would allow reusing, how a rollback should be handled for paragraphs that are shared among multiple host entities.

So Paragraphs is by design not a tool for reusing content.

But there is good news, there will be a library entity, which will make this possible:

> **Implement Library entity type**
>
> We want to make this separate entity type: \- Autosync with bundles + fields of Paragraphs \- Still add a label (plus more administrational fields if needed for managing them).
>
> A reusable paragraph will be typically stored as a clone of a previous paragraph. It is NOT a composite of the original. Reusable paragraphs have an own separate edit form and can also be creted independently through the Add form.
>
> A user can click the action "Add to library" that makes a paragraph reusable. This clones the paragraph and the original host entity will have a new paragraph instance added that contains a reference to the effective reusable paragraph.
>
> The paragraph type "From Library" contains nothing but a entity reference to the reusable paragraph. Initially, using autocomplete widget here is fine.

https://www.drupal.org/node/2843917

---
Tags: 8, paragraphs
---


# Question
Title: How to pass a value validated in Webform to the User's profile page?
There are hundreds of users on my Drupal 7 website. I don't want to manually enter the birthday value for each user in their profile. Hence why I created a webform where the user puts the user's birthday.

This value should then after validation by the current user be stored permanently in the user's profile where I created an empty birthday field.

How do I pass the value?

# Answer
> 3 votes
Using the "Webform Rules" module, you should be able to have the Rules module react on an event like "Webform submitted". So create a custom rule using this Rules Event, and then add the required Rules Actions. Here is a blueprint of these Rules Actions:

* `Fetch Entity by id`, of type user, using the `uid` of the user who submitted the form (= current user).
* `Set a data value`, for the field of the user's profile where you want to save that birthday, where the value is the birthday entered in the form.
* Possibly (not 100% sure) you may also want to add `Save entity`, to actually save that field in the profile.

### Make it right before you make it better ...

But what about a user submitting the same form again, with a different value for birthday? If you don't want that to happen, you might want to add the Flag module like so:

* Flag a user after submitting the form (using Rules), using some *global* flag.
* Improve the 1st rule above, to add a Rules Condition to verify that the user has not been flagged yet.

PS: This answer applies to D7 ...

# Answer
> 2 votes
You can alter the Webform and update the user fields. You need to use form\_alter hook for that. Added some sample code you can modify as per your need.

```
function hook_form_alter(&$form,&$form_state,$form_id)
    {
        if($form_id == 'webform_id')
        {
         $form['#validate'][] = 'hook_form_validate'; //function name
         $form['#submit'][] = 'hook_form_submit'; //function name
        }
    }

function hook_form_validate($form,&$form_state){
        // validate you dob field
}

function hook_form_submit($form,&$form_state){
    global $user;
    $account = user_load($user->uid);
          $edit = array();
        if(!empty($form_state['input']['submitted']['first_name'])){
            $edit['field_dob'] = array(LANGUAGE_NONE => array(array('value' => $form_state['input']['submitted']['dob'])));
       }
        user_save($account, $edit);
    }

```

You can also take a look on Webform Rules module.

---
Tags: users, webforms
---


# Question
Title: Create a field (defined within same module) during module installation?
Having this code:

```
function mymybase_update_7200(){
    if(!field_info_field('field_timer_exam')){
        $field = [
            'field_name'  => 'field_timer_exam',
            'label'       => 'Countdown timer',
            'type'        => 'mymy_field_countdown',
        ];
        field_create_field($field);

        $instance = [
            'field_name'  => 'field_timer_exam',
            'entity_type' => 'user',
            'bundle'      => 'user',
            'label'       => 'Countdown timer',
            'settings'    => [
                'user_register_form' => 0,
            ],
            'widget'      => [
                'type'      => 'mymy_field_countdown_widget',
                'settings'  => [
                    'display_label' => TRUE,
                ],
            ],
        ];
        field_create_instance($instance);
    }

    if(!field_info_field('field_timer_final_exam')){
        $field = [
            'field_name'  => 'field_timer_final_exam',
            'label'       => 'Countdown timer',
            'type'        => 'mymy_field_countdown',
        ];
        field_create_field($field);

        $instance = [
            'field_name'  => 'field_timer_final_exam',
            'entity_type' => 'user',
            'bundle'      => 'user',
            'label'       => 'Countdown timer',
            'settings'    => [
                'user_register_form' => 0,
            ],
            'widget'      => [
                'type'      => 'mymy_field_countdown_widget',
                'settings'  => [
                    'display_label' => TRUE,
                ],
            ],
        ];
        field_create_instance($instance);
    }
}

```

Which i think it is ok, field get created when running in the hook\_menu page callback for example, but during installation the fields does not get created.

There is no error in the watchdog nor in apache logs, the field does not exist in the user entity nor tables like field\_data\_field\_timer\_exam

The update get fired, at `system` table i can see the `schema_version` columna get updated for my module

What could be happening?

# Answer
> 1 votes
The function `hook_update_N()` only gets called by running `update.php`. You also need to implement a `hook_install()`, for example like this:

```
function mymybase_install() {
  mymybase_update_7200();
}

```

Do note that this only runs when you enable the module for the first time. So if you already enabled the module, you can test this by first disabling it and then uninstalling it. If you want to run the function each time the module is enabled, you should use `hook_enable()`.

# Answer
> 1 votes
You need to either

* Update the version number in your hook (hook\_update\_7001 =\> hook\_update\_7002)

or

* Reset the `schema_version` in the system table so that it's lower than the number in your update hook

every time you run update.php, otherwise your update function will not be executed.

---
Tags: 7, entities, installation, updating
---


title: My code is not updating in the frontend

text:
# Question
Title: My code is not updating in the frontend
I have created one content type template few days before

```
page--classroom_course.tpl.php

```

Now I'm trying to modify my code in that page but my changes are not showing in front end. Even I cleared cache everything but still the issue is same.

After that I removed that file and I again checked but it's not showing any error instead of that same output is showing.

I don't know how that is taking.

# Answer
What is the internal path of your page ? (not path alias). Based on the internal path, you can find out how to create the correct template. Or even better: This is the best solution and the most precise:

In the theme folder, you can modify template.php and implement the following hook:

```
function THEMENAME_preprocess_page(&$variables) {
  // If you have devel installed; if not, user var_dump or enable devel.
  kpr($variables['theme_hook_suggestions']);
  die();
}

```

Navigate to your page, after clear cache and you should see the theme hook suggestions and based on those, you can create your template.

E.q. If one of the suggestions is something like "page\__page\_name", then your template name will be "page--page-name.tpl.php".
> 0 votes

---
Tags: 7, nodes
---


title: Title in address bar displaying twice

text:
# Question
Title: Title in address bar displaying twice
I am having an issue that I don't know how to fix. The title of my website/pages are displayed twice and I can't figure out why. I configured my title at Configuration \> basic site settings \> name of website

Can anyone help me find what is causing this?

Any help is greatly appreciated.

# Answer
> 1 votes
This is how Drupal Title system works.

You **PageTitle| Sitename**

If you wants any modification then you can install Metatag and Token Module.

---
Tags: 8
---


title: Fields in Paragraphs twig template

text:
# Question
Title: Fields in Paragraphs twig template
I've created a paragraph type called "text\_icon\_boxes". It has 19 fields. I've added this paragraph type to one of my content types.

What I'd like to do is customise the display of this paragraph type. I've created a twig template `paragraph--text-icon-boxes.html.twig`, but the fields display "-1", etc. How do I access the paragraph fields in this twig template?

Here's a small snippet:

```
<div class="icon-box-left">
  <h2>{{ content.title }}</h2>
  <p>{{ content.text }}</p>
</div>

```

The twig template is the right one. Twig template suggestions:

```
<!-- FILE NAME SUGGESTIONS:
   x paragraph--text-icon-boxes--default.html.twig
   * paragraph--text-icon-boxes.html.twig
   * paragraph--default.html.twig
   * paragraph.html.twig
-->

```

# Answer
The field variables are not right - they need to correlate to the field name.

Example:

`{{ content.field_icon_1 }}`

`{{ content.field_icon_1_title }}`

These are the render arrays you are looking for. `{{ content.text }}` does not exist.

Also, keep in mind that these render arrays are rendering those fields - you may want to place the markup in those field specific templates.
> 7 votes

---
Tags: theming, 8, paragraphs
---