I am using Wordpress Timber which uses TWIG as the Templating Enginge. I am trying to get my array shifted, so i can then loop over it with TWIG.
array('Anna','Ben','Caroline','Emma','Daniel')
Which should end up as this:
array('Ben','Caroline','Emma','Daniel', 'Anna')
Is there a way with Timber to do this, or must I do it via PHP?
Simply solving it with PHP as DarkBee suggested.
Related
Kind of a weird and specific question but here I go.
I can currently pull all my products through YAML and through some really brute-force methods, I would be able to sort the product out by custom fields.
I have a multiple choice wizard the user has to fill and in the end, I get an object that looks something like this:
{
stoneType: ['Granite', 'Quartz', 'Glass'],
stoneFinish: ['Polished', 'Honed'],
stoneConcern: ['Floor Care'],
labels: ['Daily Cleaning', 'Stain Removal']
}
I can't (or at least I don't know how) to get this data into my HTML to use the data stored in my YAML code and render the specific products.
I believe I can solve this issue if I were able to pass the array of products into javascript using some sort of handlebars helper(?) but Bigcommerce doesn't allow for custom helper functions.
I read online that you can bypass this by installing handlebars but that is not working for me.
When I installed handlebars through NPM, I get this error:
GET http://localhost:3000/stencil/00000000-0000-0000-0000-000000000001/dist/theme-bundle.main.js 404 (Not Found)
Is there a way for me to get custom helper functions working or another possible idea to sort & filter the products?
Thank you, appreciate the help.
EDIT: I have also tried manually downloading Handlebars.js including the file but I get the error Handlebars is not defined. I must be doing something wrong...
i have used laravel shortcodes (https://github.com/webwizo/laravel-shortcodes) with success, it is a nice bundle.
the question is: is there any bundle like this for symfony 3.x?
what this essentially do is take formatted string like [myString] with some optional parameters like [myString param1="abc" param2="def" ...] from a rendered blade / twig and looks for a controller / function etc. to resolve "myString". it passes the params to the controller, and the whole [...] stuff is replaced with the returned output. and it is done recursivly, so the result may contain another [myString2 ...] and so on. this is very useful in CMS building.
does anyone know anything like this for symfony?
There is a bundle that looks exactly what you are searching for:
https://github.com/mweimerskirch/MWShortcodeBundle
What is best way to retrieve Drupal 8 taxonomy terms and pass array to twig template?
Now I have:
In template.theme
function template_preprocess_page(&$variables) {
$variables['some_term'] = \Drupal::service('entity_type.manager')->getStorage("taxonomy_term")->loadTree('some_term', $parent = 0, $max_depth = NULL, $load_entities = FALSE);
}
Now in page.html.twig I can access {{ some_term }} array.
I feel that something is wrong about this. What is the best way to achieve this? I just need an array of selected taxonomy terms in page.html.twig. I want to use it to build custom HTML code.
Equivalent function in Wordpress is simple get_terms().
Your code seems to be OK.
Please check next:
Are you getting taxonomy tree array values in template_preprocess_page?
If not ($variables['some_term'] should not be empty array)
check if you are loading correct vocabulary with "...->loadTree('machine_name_of_vocabulary'..."
If yes check what twig is getting in page.html.twig You can check with: {{ dump(some_term) }}. Probably you will need to process array to get only for example list of term names.
Did you cleared Drupal cache?
Is there a twig template engine's equivalent function or filter of PHP's ceil function. I looked in the documentation but couldn't find a ready made filter or function.
Maybe you could try using the // operator, like this:
{{20 // 1 + 1}}
If this is not short enough for you, then you should probably write your own twig extension
Twig has recently added this feature:
{{ (3.333)|round(0, 'ceil') }}
Check out the documentation here
I have a drupal template. I want to know what are the names of the active variables using php..
How do I achieve that ?
If you're just looking to get which variables have been defined, you can use PHP's function get_defined_vars:
print_r(get_defined_vars());
http://php.net/manual/en/function.get-defined-vars.php
If your after Drupals globals, here they are...
http://api.drupal.org/api/drupal/globals/7