Using the HTML Helper For Code Igniter - codeigniter

I have a few questions regarding the HTML Helper on the code igniter website.
http://codeigniter.com/user_guide/helpers/html_helper.html
It shows where you can echo out the doctype but then my thinking is you'd have to do the manual html code for like the head tag, body tag and title tag but it has the meta tag.
So what would be the point in doing this?
<?php echo doctype(); ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php
echo meta('description', 'My Great site');
echo meta('Content-type', 'text/html; charset=utf-8', 'equiv');
?>
</head>
<body>
</body>
</html>

In a model pop those meta tags into an array and sent it to your view. Then use a foreach to output your meta tags, and wha-la many lines of meta turn into one line of php, and your meta tags can easily be edited in your model.

Related

Extend A View With Thymeleaf

is it possible extend a shared view with thymeleaf?
I saw that is possible use framents but is not what I want.
Instead I want something similar to .NET MVC, with something like #RenderBody() and another view that extend the shared view by including the shared view.
You can use the Thymeleaf Layout Dialect to extend a view.
Layout page
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
...
<body layout:fragment="body">
...
</body>
</html>
Content page
In your content page, you refer to the layout (decorator) page using the layout:decorator attribute.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="layout.html">
...
<body layout:fragment="body">
<p>Actual page content</p>
</body>
</html>
It is possible to have multiple fragments in one page.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
...
<body>
<div layout:fragment="content"></div>
<footer layout:fragment="footer"></footer>
</body>
</html>

Blade is not working on laravel 4

This is what I have written in my view
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel PHP Framework</title>
</head>
<body>
<div class="welcome">
{{Hi everyone}}
</div>
</body>
</html>
It outputs {{Hi everyone}}
why is it not working ?
First: The view file should be named with a ".blade.php" after it.
Second: The {{ $str }} blade command it's only a shortcut to <?php echo $str ?>. That been said, if you want to just print a string, you should put it between " or even ', as you would probably do with a regular echo statement. Something like echo "Hi everyone";.
That SHOULD work on your case! :D
The file needs to be renamed as filename.blade.php. Check if the file had been named as per the convention rules.
You should call it in your route or controller with return View::make("hello"); etc. Also #Its Aafrin described, your file needs to be renamed as filename.blade.php.
There are diffrent ways to print. However you are just missing quotes. I have listed other methods also...
1. {{'Hi every one'}}
2. <?php $str='hi every one' ?> {{$str}}
3. <?= 'Hi every one' ?>

How do I remove the slash that appeared right after the body tag?

My website was working fine, when all of a sudden a slash appeared right after the body tag. I tried to find out what was wrong but I had no luck.
How to fix this?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Toucan | <?=$title?></title>
<?php $this->load->view('include/head'); ?>
</head>
<body>
<div id="container">
<?php $this->load->view('include/header'); ?>
<?= $slideshow ?>
<table id="main">
<tr>
<?php if ($sidebar):?>
<td width="150px"><div id="sidebar"><?= $sidebar ?></div></td>
<?php endif; ?>
<td><div id="content"><?= $content ?></div></td>
</tr>
</table>
<?php $this->load->view('include/footer'); ?>
</div>
</body>
</html>
You should take a look at the end of your controller to check if you have a PHP closing tag : ?>. And maybe something like / after it...
This is good practice to omit the PHP closing tag at the end of your scripts.
I just google your webpage (toucan-eng.com) and a slash is showing in the main webpage. The title tag should be inside the head tag and then you need to put the body tag. Hope this can help you

How to insert whole html page (<html> tag) in ckeditor?

I am trying to add a full html page into ckeditor for some editing via js.
Specifically, I execute the command
oEditor.insertHtml("<html><head><title>Hello</title></head><body><div>hello</div></body></html>");
But the result I get is the following:
<p>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
</p>
<p>
<title></title>
</p>
<div>
hello</div>
The mode I use is:
config.fullPage = true
I tried also with fullPage = false, but not success.
Is there any way to insert to ckeditor a full html page?
Thanks a lot in advance!!
The insert* methods append the data to the editor contents, but if you want to replace the whole content then you must use setData.

codeIgniter form validation doesn't work when passing view as string

I am currently learning CodeIgniter and using it for a small project. I would like to make a template so that I don't need to write repeated code for the views. I like jruzafa's answer in this post: How to Deal With Codeigniter Templates?
In controller:
//Charge the view inside array
$data['body'] = $this->load->view('pages/contact', '', true);
//charge the view "contact" in the other view template
$this->load->view('template', $data);
In view template.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es">
<head>
<title>Template codeigniter</title>
</head>
<body>
<div>
<?=$body?>
</div>
<div class="clear"></div>
<div>Footer</div>
</div>
</body>
</html>
$body is the view contact.
But now I face a problem. The form validation doesn't work if I pass the form_view as string to $data['body']. Is there any way to work around it?
Thanks.
Try loading the body content within the template itself. This should allow you to be more selective with your output:
In controller:
// Set the path to body content inside the $data array
$data['path_to_body'] = 'pages/contact';
$this->load->view('template', $data);
In view template.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es">
<head>
<title>Template codeigniter</title>
</head>
<body>
<div>
<? $this->load->view($path_to_body) ?>
</div>
<div class="clear"></div>
<div>Footer</div>
</div>
</body>
</html>

Resources