I want to print title in my view (Template) in CakePHP3.
$this->fetch('title') is working fine in element and default.ctp but when using this in view it is printing nothing.
How could I print title in view using $this->fetch('title')?
In your view file you should assign some value to the title variable
$this->assign('title', 'Example title text');
Than in your template you should have
<?= $this->fetch('title') ?>
Related
I am working on blog section of a project. I integrated ckeditor and saved data to database. When i display it in php it shows plain text instead of html. I have tried different ways but couldn't resolve the problem. Please some one guide me. thanks.
my function to save data in database
public function store_blog(Request $request){
$fname=null;
if($request->hasFile('image')){
$file=$request->file('image');
$fileName=uniqid().'.'.$file->getClientOriginalExtension();
$file->move(public_path('uploads/blogs/'),$fileName);
$fname=asset('uploads/blogs/'.$fileName);
}
$bbody=$request->blog_body;
$bbody = trim($bbody);
$bbody = stripslashes($bbody);
$bbody = htmlspecialchars($bbody);
Blog::create([
"title"=>$request->title,
"short_description"=>$request->short_desp,
"body"=>$bbody,
"cover_image"=>$fname,
"slug"=>str_replace(" ","_",$request->title),
]);
return redirect()->route('blog_index')->with('success','Blog created successfully');
}
this function saves content successfully. But when i fetch and display in laravel blade view. Ckeditor content displayed all html as plain text/string. How can i force this to render html.
function to fetch blog from database
public function show_Ablog(Request $request,$slug){
$blog=Blog::where('slug',$slug)->first();
return view('website.showAblog',compact('blog'));
}
in my blade view
<div class="col-lg-12 dat">
{{($blog->body)}}
</div>
i have tried all functions like
htmlspecialchars
htmlentities
how could i resolve this.
When your data contains HTML tags then use
Write your code in blade file like
{!! $blog->body !!}
Try this with php syntax like
{!! $blog->body !!}
Note: Make sure that your editor sending proper html content?
I have created a custom field for Post type which I want to show up in the loop which I managed to do with the help of Advanced posts of Ultimate add-on for beaver builder. Now I want the link to be embedded in a button so that users may click the button and it open ups the value under url custom field.
Since I do not prefer core php method for greater control over my web content hence want to know if there is anyway around in html, bootstrap or shortcode to do so ?
I'd recommend setting up a Link field, and following the examples from ACF, pass the $link_url into the anchor's href, click here . Source: ACF | Link
Here's the code they recommend using, which is of the same format that I generally use:
<?php
$link = get_field('link');
if( $link ):
$link_url = $link['url'];
$link_title = $link['title'];
$link_target = $link['target'] ? $link['target'] : '_self';
?>
<a class="button" href="<?php echo esc_url($link_url); ?>" target="<?php echo esc_attr($link_target); ?>"><?php echo esc_html($link_title); ?></a>
<?php endif; ?>
If you're using the fields within a Repeater or a Group, use get_sub_field() instead of get_field().
I am trying to create a Yii2 theme, & would like to set a variable that with scope of the entire views folder. For a single page theme I used...
$assetDir = Yii::$app->assetManager->getPublishedUrl(
'#vendor/path/to/assets/folder'
);
in index.php & I then I accessed it using...
<img src="<?= $assetDir ?>/img/image.jpg" alt="">
For partials I am able to pass that using...
<?= $this->render('_partial.php', ['assetDir' => $assetDir]) ?>
I am now wanting to do similar in a theme with multiple pages & cannot find how to do that without setting $assetDir in each page. I imagine it would be set in the main.php layout.
Use params array for this as stated in Sharing Data among Views.
The view component provides the params property that you can use to share data among views.
For example, in an about view, you can have the following code which specifies the current segment of the breadcrumbs.
$this->params['breadcrumbs'][] = 'About Us';
Then, in the layout file, which is also a view, you can display the breadcrumbs using the data passed along params:
<?= yii\widgets\Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
I am using CKeditor for my Laravel 5.1 custom CMS. When I request content of stored pages in the database on my view, they appear with HTML tags like <p>Hello world</p>.
I have used html_entity_decode() with and without the charset specified to no avail.
It is also worth mentioning that I use Blade template engine at my view. Hence, my demo code looks like
$post->content = '<p>Hello world</p>'; // from the database from controller
{{html_entity_decode($post->content)}} //did not decode
I also tried using it in my controller instead and it did not change anything like this
$post->content = html_entity_decode($post->content); //before sending it to the view
I need your help to address this issue.
Instead of doing {{html_entity_decode($post->content)}},
try this:
{!! $post->content !!}
More info here https://laravel-news.com/2014/09/laravel-5-0-blade-changes/
you can do this in the controller
strip_tags($post->content);
or if you use in blade
{{ strip_tags( $post->content ) }}
see more info here strip_tags
I am currently working on a semi dynamic page where I use some GET functionality to personalize it. I also echo the date a couple of places. At the bottom of this page, I would like to have a button that gives the visitor the option to download/open this page as PDF. Without the header. I have integrated DOMPDF, but I simply cant get it to work properly and need some help. I have tried a couple of things found here on Stackoverflow, with no success.
In basic, I need the whole page printed in the PDF, but it should not open when page is loaded. But triggered by the button. And then without the header (one spesific div). Is this possible?
<?php
require_once("dompdf/dompdf_config.inc.php");
$html =
'<html><body>'.
'<p>This is a test for '.
'<?php echo htmlentities(substr(urldecode($_SERVER["QUERY_STRING"]), 1)); ?> </p>'.
'<p>Thank you for reading.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("the_inquiry.pdf");
return true;
?>
<html>
<body>
<div class="shouldnotPrintToPDF">
Content.
</div>
<div class="shouldPrintToPDF">
Sensitive content.
Open or save as PDF
</div>
</body>
</html>
This is basically our one page presentation. And contains a lot of text, so I will not present all of that here. But in this way, I have to write the page twice, in $html = as well as inside the actual tag. And the PDF save/open option pops up right from the start, which it should not. I also wish to append the echo htmlentities part to the actual pdf-name.. is this possible? The PDF opens and contains what put into the $html = just fine. But not triggered by the link.
Update:
When i do exactly what you perform here, I get an error "The requested URL /inquiry.php&pdf=1 was not found on this server." I have the page I am trying to print in pdf on root level, but the DOMPDF is in /dompdf.. I dont know if that has anything to do with it?
Update:
When i edited the link, i get all this information up in a new page, like below.
[_parse_properties(margin:=1.2cm)(empty)_parse_properties]
[_parse_sections[section[_parse_properties(display:=-dompdf-page)
(counter-reset:=page)(empty)_parse_properties]#html#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]
_parse_sections][_parse_sections[section[_parse_properties(display:=block)
(empty)_parse_properties]#div##map##dt##isindex#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]
_parse_sections][_parse_sections[section[_parse_properties(page-break
-before:=avoid)(display:=block)(counter-increment:=page)
(empty)_parse_properties]#body#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]_parse_sections]
[_parse_sections[section[_parse_properties(display:=block)(margin:=1em
0)(empty)_parse_properties]#p##dl##multicol#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]_parse_sections]
[_parse_sections[section[_parse_properties(display:=block)(margin-left:=40px)
(empty)_parse_properties]#dd#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]_parse_sections]
[_parse_sections[section[_parse_properties(display:=block)(margin:=1em
40px)(empty)_parse_properties]#blockquote#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]_parse_sections]
[_parse_sections[section[_parse_properties(display:=block)(font-style:=italic)
(empty)_parse_properties]#address#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]_parse_sections]
[_parse_sections[section[_parse_properties(display:=block)(text-align:=center)
(empty)_parse_properties]#center#section]
Do you have any idea what it might be caused by?
Breakthrough:
When I activated DOMPDF_DPI it actually opens as PDF, but now all of the text comes on first line of the second page of the PDF. Like, all the text comes out on top of each other. Also, when it opens the PDF, the ?&pdf=1 are included in the htmlentities query string, which looks very messy since it is supposed to be a personalized page as well as the PDF.
You can set dompdf to parse CSS #media queries for standard media types (screen, print, voice, etc.). By default dompdf parses the "screen" media type styles, but you can change this in the configuration file. See the DOMPDF_DEFAULT_MEDIA_TYPE configuration setting. Then you just need to pass the original URL querystring with an appended variable telling the page to render to PDF. If your original URL is something like the_inquiry.php?name=Joe then your PDF URL could be the_inquiry.php?name=Joe&pdf=1.
Your code would then look similar to the following:
<?php
ob_start();
?>
<html>
<head>
<style>
#media print {
.shouldnotPrintToPDF, .pdflink { display: none; }
}
</style>
</head>
<body>
<div class="shouldnotPrintToPDF">
Content.
</div>
<div class="shouldPrintToPDF">
Sensitive content.
Open or save as PDF
</div>
</body>
</html>
<?php
if ( isset( $_GET['pdf'] ) ) {
require_once 'dompdf/dompdf_config.inc.php';
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("the_inquiry.pdf");
}
?>