Drupal 8 Render Content in Twig Template - php

I would like to render a simple plain-text or html output in my twig template ( page--front.htmltwig ).
I have this kind of HTML :
<header class="intro-header" style="background-image: url('themes/custom/tommiecrawford/images/home-bg.jpg')">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="site-heading">
{{ HERE I WANT TO RENDER SOME HTML FROM DRUPAL }}
<hr class="small">
<span class="subheading">A Clean Blog Theme by Start Bootstrap</span>
</div>
</div>
</div>
</div>
What is the best way to create a simple html output in drupal and then render it in this twig template?
Do i need to create a custom block or something like that? And how can i render this in the template so i can make the output dynamic?
Many thanks

Alright, i found out how the template system actually works.
You need to enable twig debug to see what template is used. In this case it was block--slogan.html.twig.
So i just need to overwrite that template in mine custom templates directory.
After that i just could use the {{ content }} method to display the block content and style it a little bit.

Related

Is is possible to get WPBakery generated rows as a variable?

I'm creating custom elements in WPBakery (formerly Visual Composer), but encountering issues with its rendered markup.
For example:
I've created a custom element called text. text currently spans 12 columns in the WP admin:
The rendered markup for this looks like:
<div class="row justify-content-center">
<div class="text">
<div class="text-left container">
<h2>This is header</h2>
<p>This is content</p>
</div>
</div>
<div class="col-sm-12">
<div class="vc_column-inner">
<div class="wpb_wrapper"></div>
</div>
</div>
</div>
As you can see, it's creating an empty col-sm-12 div and not even applying the column styles to text.
Ideally what I want to do is get the column WPBakery is generating and place it in a variable.
This way, I can do something along the lines of:
<div class="text <?php echo $column; ?>">
I think this will be handy when a user eventually decides they want two text blocks next to each other:
So each text block will be col-6.
To summarise, I'm trying to figure out why Bakery is outputting an empty div with columns rather than to wrap around my text block? As I'm not sure why this is happening, the only solution I can think of is to get the column data as a variable and then echo is in the text block.

I would like to add an additional row to my Wordpress BootStrap Navigation

I have a simple website which I would like to add a row above the navigation that would contain a phone number and maybe some social links.
I am a theme called Hestia Pro and cannot find where to add this extra row
I am looking for some pointers as to where this would get added in the sites theme.
The website is www.gpoint.co.uk
Craig
Your theme is built with bootstrap
you can check your theme files and go to header.php
check the the tag <header>
and inside it you can add:
<header>
.....
<div class="row">
<div class="container">
<div class="col-sm-4">
Telephone
</div>
<div class="col-sm-4">
email
</div>
<div class="col-sm-4">
support
</div>
</div>
</div>
</header>
thats it :)

Site template not working in wordpress

Okay, so I'm developing a site in wordpress and I have two file templates "Default Template" and "Shop" in both templates I have;
<?php include('breadcrumbs.php'); ?>
and inside the 'breadcrumbs.php' file I the following;
<div class="breadcrumbs">
<div class="container">
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<?php
if (function_exists('show_full_breadcrumb')) {
show_full_breadcrumb();
}
?>
</ol>
</div>
</div>
</div>
</div>
Now these breadcrumbs display properly if it is in the 'default template' like this;
But on the shop page display like this and I have no idea why as they're both including the same file;
now I'm not sure if this would affect much of it but I am also using WooCommerce.
Hopefully someone can help! thanks in advance!
It's definitely a css issue. Something is overriding the styling on that shop page. Use firebug to diagnose the breadcrumbs. Or provide a link so I can look at it. But Firebug will show you the ul styling right on the breadcrumbs and you can A/B between the default and the shop template. Should be an easy fix with the CSS
Hope this helps.

Method Illuminate\View\View::__toString() must not throw an exception when loading views inside view in Laravel

I am loading a header and footer in each page without using blade and just using echo View:make('templates/header'); and at the end of the page likewise with the footer.
I am loading these same header and footer views in exactly the same manner in other views without problems, but when I call this particular view from my controller, I get this very non-informational Laravel error message. It's very basic HTML right now as I'm still in the building/testing phase. I don't know why loading the header and footer views in other views I'm using works, but here they're crashing.
Here's the code:
<?php
echo View::make('templates/header');
?>
<div class="row">
<div class="col-md-5 col-md-offset-3">
<h1>Record Saved!</h1>
</div>
</div>
<?
echo View::make('templates/footer');
Is there any way to get more information out of Laravel to find out what it's not liking?
__toString() calls the render() method on View (source). the exception is therefore thrown within templates.footer or templates.header.
In blade template file, You do not need to write <?php ?> Tag.
also use include instead of View::make in blade file.
#include('templates.header');
<div class="row">
<div class="col-md-5 col-md-offset-3">
<h1>Record Saved!</h1>
</div>
</div>
#include('templates.footer');
Note: Blade file must has extension .blade.php
Hope it will help you :-)

create a twig filter that wraps output in HTML

I created a filter in Twig that wraps some HTML around the output. E.g.
{{ 'this is a "test"'|display }}
outputs
<div id="container">
<div id="content">
this is a "test"
</div>
<div id="toolbar">
edit
</div>
</div>
The dilemma is, I would like that subsequent filters are applied only on the original content, and not on the entire html. E.g.
{{ 'this is a "test"'|display|upper|e }}
outputs
&LT;DIV ID=&QUOT;CONTAINER&QUOT;&GT;
&LT;DIV ID=&QUOT;CONTENT&QUOT;&GT;
THIS IS A &QUOT;TEST&QUOT;
&LT;/DIV&GT;
&LT;DIV ID=&QUOT;TOOLBAR&QUOT;&GT;
&LT;A HREF=&QUOT;/EDIT.PHP&QUOT;&GT;EDIT&LT;/A&GT;
&LT;/DIV&GT;
&LT;/DIV&GT;
but as you can imagine, I would prefer the output like this
<div id="container">
<div id="content">
THIS IS A &QUOT;TEST&QUOT;
</div>
<div id="toolbar">
edit
</div>
</div>
Changing the filter order to
{{ 'this is a "test"'|upper|e|display }}
would work for the upper filter, but not for the escape filter, because it places itself always at the end of the filter queue. Also it should work with autoescape=true.
Reading the twig documentation, I can't find a standard way to do what I want. Has someone maybe tried something similar? Or has someone an idea to work around the problem?
Thanks in advance!
Try:
{{ 'this is a "test"'|upper|e|display }}
Filter your content in first place and then wrap it.

Categories