Call a .ctp file from a layout file with CakePHP - html

Is it possible to call a .ctp file from a layout which is also a .ctp file?
I have a default layout with the topbar, the footer and of course the variable $content_for_layout in the middle. I would like to dispatch the topbar and the footer into two others different .ctp files and I would like to call them from my layout.

You can use elements.
<?php
echo $this->element('topbar');
echo $content_for_layout;
echo $this->element('footer');
?>

You can use elements or, in CakePHP 2.1, you can check out blocks.

Related

Dompdf related issues style, link, table goes out and related issues

Q. 1:
DomPDF table goes out of pdf from print report if table is wider
I am using dompdf and it works fine for small wider tables but it goes out of pdf page when it's too much wider so any solution is there I have looked at many places but couldn't find the solution.
Please find attach photo of issue:
Q: 2: Is Dompdf Support Bootstrap:
I have a bootstrap layout which doesn't seem supportable as I have added all required bootstrap css on top of the page but they are not working like hidden-xs which I really wanted to apply if the table is too wider then hide few columns like above Q-1 case.
Q: 3: Color not applied even specified in table inline Style:
Ok, so now my turn to explain how I did the code before Q-3 so I have one page called index.php where I have a table and all css styles on top. Now I specify table inside div like following:
<div id="htmlData"><table class="my bootstrap table"></table></div>
So now how I print things well I wrote one script on the same index.php page:
<script>function printout(){ $.ajax({ POST: '../dompdf/print_report.php' })}
Now this print_report.php file contain the code which will like the following:
Print_report.php:
<?php
require_once("dompdf_config.inc.php");
ob_start();
?>
<html>
<head>
<link href="**if I define any link path like http://bla.com/index.css - then it not work so I define styles on page level**" ....>
<link/>
</head>
<body>
<?php
echo $_POST['htmlData']; //which I send through ajax
?>
</body>
</html>
<?php
$html = ob_get_clean()
...rest of the code.....to print and save pdf to a file
?>;
However, Please help me out in this option as I believe DOMPDF is the best on net and I really don't want to lose using it so if anyone out there any help me than. Thanks a lot in advanced.

Joomla link to barebones article content

I know a trick to make link to article without template (tmpl=component), but I see that it still links some styles:
index.php?option=com_content&view=article&id=171:uvjeti-plaćanja&catid=19:poliklinika&Itemid=101&tmpl=component
Is it possible to create link to just bare bones data you'd see in content editor for example?
It would be prefferable if nothing else but pure article content is returned. No html, body, head ... tags.
I have ended up creating file raw.php which contains following code:
<?php defined( '_JEXEC' ) or die( 'Restricted access' );?><jdoc:include type="component" />
I have placed this into my template folder and I can just call it with following url:
/?option=com_content&view=article&id=171&catid=19&Itemid=101&tmpl=raw
Analog to that you one can make new.php, place it to folder of current template in use and call it with &tmpl=new argument.

Remove P tags with multiedit plugin

I'm using the multiEdit plugin to create some content regions on a template.
One of those region is for some photos that are going to be using jQuery cycle to rotate through the images.
But, as usual, Wordpress (or the editor rather) is wrapping all of the images in a <p> tag.
I've used the functions hack from CSS-Tricks to remove the <p> tags from the content:
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
But, from what I can tell, it only looks for the_content and not for anything else.
Multiedit uses this: <?php multieditDisplay('name_of_region'); ?> to display the content block in the template.
So, I tried to change the function to this:
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('multieditDisplay', 'filter_ptags_on_images');
But no such luck.
So, I'm not so sure if I'm missing something or just going about it the wrong way.
Ok, well I found a workaround.
I did a write up about it here:
http://ultraloveninja.roon.io/filtering-paragraph-tags-with-the-wordpress-multiedit-plugin
Instead of placing multiEdit fields in your template like this example
<?php multieditDisplay('Top'); ?>
You could prevent the auto print by passing true as the second parameter like this
<?php echo multieditDisplay('Top', true); ?>
So if you want to strip ALL tags from the output, then try this
<?php echo strip_tags(multieditDisplay('Top', true)); ?>
If you want to include certain tags then provide a list of tags to include and pass it as a parameter to strip_tags like this
<?php echo strip_tags(multieditDisplay('Top', true), '<p><a>'); ?>

Is it wrong to define ID in body tag for CakePHP?

I am working on a project in which I define ID inside of a <body> tag. For different pages I define different IDs, & I always follow this structure for my all projects. But in our new project which is in CakePHP, my developer said to me that I should never use ID inside the body tag for a CakePHP project.
When I asked him why, he said because we can generate ID through CakePHP.
I don’t know so much about CakePHP, but I think we can define ID inside the body tag for CakePHP & other languages also.
Please provide some links or articles & your suggestions about it.
Thanks in advance :)
You can define id's in your HTML mark-up that's not a problem. But from your question it looks like you are defining id's as an attribute to body tag?
Well you can define id's in body tag. but the problem is in cakePHP you have layouts which usually contain the wrapping HTML of your views, like header, footer etc. So you can not manually define static id's inside body tag for different pages, well you can but then you won't be using layouts.
What your developer telling you I guess is the use of (uuid) unique id's a feature provided by cakePHP to generate unique id's for DOM elements.
you can generate id's via uuid(string $object, mixed $url) function in your views.
To learn more visit : http://book.cakephp.org/view/1091/uuid
You could dynamically add classes to your layout like so:
<?php
$classes = String::insert(':plugin :controller :action', array(
'plugin' => $this->plugin,
'controller' => strtolower($this->name),
'action' => $this->action,
));
?>
<div id="content" class="<?php echo trim($classes); ?>">
<?php echo $content_for_layout; ?>
</div>
This would allow you to namespace your CSS declarations:
.blog.posts.view h2 {
/* ... */
}
Note: IE6 doesn't properly support chaining of multiple classes to select a single element, though there are some Javascript shims if you are still supporting it.

How can I add HTML near the </body> tag within a Joomla Module?

I am quite new to using Joomla. I have created a custom module, however I would like to add some code near the </body> tag (or near the opening <body> tag) so it is guaranteed to be not nested in any tables whatsoever that might be in the template.
I have located details on how to do this within a content plug-in, however I would like to just have the module.
Any ideas? Thank you.
If the entire module is to go just before </body> then you will need to create a module position in your template. In the file /templates/[name]/index.php put this in the required location:
<jdoc:include type="modules" name="endofpage" />
Now when you add the module you can put it in the position "endofpage" (or a better name if you choose).
Otherwise, if your main module content is to be within the regular design, you will have to create two modules or use the plugin method like you said. There is no way to inject content into two different parts of a page with one module (unless you use Javascript to generate it).
I'm not quite sure I follow why what DisgruntledGoat suggested won't work.
If you want to add code immediately at the start of the
1) Create a new module position in your template.xml (call it startofpage, or endofpage)
2) In you template index.php place the code
3) Depending on what you want to output, change the style attribute of the module
</head>
<body>
<jdoc:include type="modules" name="startofpage" style="xhtml" />
...YOUR CONTENT IN HERE
<jdoc:include type="modules" name="endofpage" style="xhtml" />
</body>
</html>
Stuff on a joomla website is placed inside positions, so it depends on the positions your template has.
So, if there is an empty position available (that comes after all the other positions), placing your module there will have it as the last thing before the end of body.