I have a viewSuccess.php template that renders some HTML
What I'm looking to do, is to try and capture this HTML and save it as a PDF.
I have an action called executeSavePage which currently saves a PDF.
I could use something like ob_start() and ob_get_contents() in the view template, but how would I then send this to my savePage action?
Thanks
You can use the get_partial() function (part of the Partial helper)
$html = $this->get_partial('view',array('item1' => 'value1'));
$html will contain the result of the partial rendering
Related
I search to use underscore or dot instead of brackets with FormType in URL query with GET method.
Current
I've actually this URL when I submit my form:
/path?fieldName%5BsubFieldName%5D=toto
Or this (decoded):
/path?fieldName[subFieldName]=toto
Expected
I'd like to have this:
/path?fieldName_subFieldName=toto
Or this:
/path?fieldName.subFieldName=toto
Tried
I tried a few options in the form configuration but I don't know what they correspond to, and I don't know where to google (what terms to use).
It's the normal behaviour of Symfony Form Component.
To avoid this, you should use named form builder, like this :
public function controllerMethod(FormFactory $formFactory) {
$form = $formFactory->createNamed(
'', // Your form name
MyFormType::class, // Your form type
[], // data
[] // form options
);
// Do something
}
For the button, you have to remove it from your Form class (i mean, the SubmitType one), and add it manually tou your html (with classical <button></button> inside of your form rendering)
I could add extra functionality to a dataobject if I extend it with a dataextension. For example I've got an Item which gets extended from a module with stock keeping functionality. Let's say the Item also gets's extended form a few other modules.
After the extension with the stock keeping functionality, I'd like to display the availability of the item in the frontend, for example with a green/red dot. How can I get this dot's markup inside my template for the detail page(ItemPage.ss) and the include (Item.ss) for the overview page of items without overwriting the whole template. Just adding this one part, like the way I extend a function on my base class?
That could be a way to add extra markup to the original template.
Inside dataobject or global dataobject extension
public function ExtraTemplateHTML($position) {
$html = null;
foreach($this->owner->extend('updateExtraTemplateHTML') as $positionBlocks) {
if(isset($positionBlocks[$position])) {
foreach($positionBlocks[$position] as $htmlBlock) {
$html .= $htmlBlock->getValue();
}
}
}
return $html;
}
Inside the specific dataobject extension
public function updateExtraTemplateHTML($htmlBlocks) {
$viewer = new SSViewer(__CLASS__);
$html = $viewer->process($this->owner);
$htmlBlocks['bottom'][] = $html;
$topHtml = HTMLText::create();
$topHtml->setValue(123);
$htmlBlocks['top'][] = $topHtml;
return $htmlBlocks;
}
Original Template
$ExtraTemplateHTML(top)
...
...
$ExtraTemplateHTML(bottom)
Extension Template
Than just write a new template for your extension with the content you would like to add.
You cannot partially change a template, you can only substitute the template with another. So, keeping this in mind you should keep modular architecture with many logical includes.
Another possible way to extend existing content is using DOM and javascript. But you should think about side effects. For example if you add extra textual content then it won't be visible by crawlers and will effect your SEO. But for decorative enhancements, like adding extra coloured dot, this approach will work.
In my functions file I have this:
function caption_shortcode( $atts, $content = null ) {
return '<span class="caption">' . $content . '</span>';
}
add_shortcode( 'caption', 'caption_shortcode' );
In the CMS page editor I have this:
[caption]My Caption[/caption]
This page is utilizing a custom template file template-mypage.php. My question is: I would like to create multiple short codes types within the CMS such as:
[caption1]My Caption[/caption1]
[caption2]My Caption[/caption2]
[caption3]My Caption[/caption3]
then in my template-mypage.php... I would like to selectively choose where to place [caption1], [caption2], [caption3]... for example [caption1] will go somewhere on the top... [caption2] in the middle and [caption3] towards the bottom of the template-mypage.php, all seperated by some huge chunks of HTML content. I do not want to write any HTML within the WP CMS... all HTML should be written in the template-mypage.php.
Currently I believe WP limits shortcode output to come out of the_content(); Is it possible to do something like the_content_of_caption1(), the_content_of_caption2(), the_content_of_caption3()?
Thanks please let me know!
this product does this perfectly
http://wordpress.org/plugins/multiple-content-blocks/
I've written a WordPress plugin, which enables the admin to generate some html-code into the WYSIWYG editor. There are buttons in this html code which have a particular action - this is done via jQuery on the single page.
However, I need the page id as an input for jQuery; I want to add a hidden input field with the page id to every page.
Is there a hook which adds a particular html code to every page, so that i can access it via jQuery?
Solved:
function add_to_content($content) {
$content .= "<input type='hidden' name='post_id' value='".get_the_ID()."' />";
return $content;
}
add_filter('the_content', 'add_to_content');
I'm working on a Drupal 7 website. I need custom layout for some pages. so I created page--customContentTypeName.tpl.php file and it addresses perfectly.
The problem is, I need to display some fields in page tpl. The code below works fine in node tpl, but page tpl :/
<?php print $content['field_images']['#items']['0']['filename']; ?>" />
How can I call custom fields into page tpl?
Appreciate helps!! thanks a lot!!
** SORTED **
with custom field editing... here is the tutorial video: http://lin-clark.com/blog/intro-drupal-7-theming-fields-and-nodes-templates#comment-54
For page.tpl.php
if you access the node directly you can use $node variable
$node['field_images']['und'][0]['filename']
else use $page variable.
$page['content']['system_main']['nodes'][1]['field_images']['#items'][0]['filename'];
but remember in a page variable you might have more than one node.
The structure changed in 7, the field is keyed by language first ("und" by default which means "undefined"), then you can follow this example:
// Array of Image values
$images = $node->field_images['und'];
//If you don't know the language, the value is stored in:
$node->language
// First image
$image = $images[0];
// If you need informations about the file itself (e.g. image resolution):
image_get_info( $image["filename"] );
// If you want to access the image, use the URI instead of the filename !
$public_filename = file_create_url( $image["uri"] );
// Either output the IMG tag directly,
$html = '<img src="'.$public_filename.'"/>';
// either use the built-in theme function.
$html = theme(
"image",
array(
"path" => $public_filename,
"title" => $image["title"]
)
);
Note the usage of the uri instead of the filename for embedding the image in a page because the File API in Drupal 7 is more abstracted (to make it easier to integrate with CDN services).
there are 2 useful modules in drupal for theme developers:
Devel and Theme_developer
Devel module provides a function called dsm() .
using dsm you can recognize that how elements are stored in different objects.
like nodes or ...
for example you can use this statement : dsm($node)
the structure of any nodes in the page will show up in the message box.
you can type the statements in your codes.