Wanze
PW-Moderators-
Posts
1,116 -
Joined
-
Last visited
-
Days Won
10
Everything posted by Wanze
-
Hi nfil, Thanks and good to hear that it works on the live host. Though it's strange that it does not work locally, images are working fine here, also using MAMP. Using the file:// protocol should not be necessary. Another possibilty could be that you'v seen a cached version, if you enable the debug mode the module makes sure you always get a fresh PDF file.
-
Yep, looks fine to me! Another approach could be to use ProcessWire's prepend template file option. This way, you can populate the variables in your global template and overwrite them in the controllers, if needed. Let's assume that we have a variable 'content' and 'sidebar' in our global template. // Populate default values in prepended template file, e.g. _init.php $view->set('content', $page->body); $sidebar = $factory->load('chunks/sidebar'); $sidebar->set('a_variable', 'a_value'); $view->set('sidebar', $sidebar->render()); Now in the home controller, the content variable is more complex, we overwrite it: // In home.php the content variable is pouplatet differently $home = $factory->load('home'); $home->set('images', $pages->find('template=gallery,sort=-created,limit=3'); $view->set('content', $home->render()); It works the same, switching the template engine is possible as long as you use the same template filenames (the ending/suffix can be different) and identical variable names. This is possible because behind the API variable is not directly the engine like Smarty or Twig but sort of a 'gateway class' that talks to those engines. Notice that in my examples above I loaded the template files without the suffix, just the filename. Depending on the active filename, the correct template is loaded. As an example, you could (though this is probably a very rare need) store your templates like this: For the ProcessWire engine: In folder /site/templates/views/ For the Smarty engine: In folder /site/templates/smarty/ Now if ProcessWire is the active engine and you load the template 'home', a file in /site/templates/views/home.tpl.php gets loaded (whatever you've configured as template file suffix). If Smarty is active, the file /site/templates/smarty/home.tpl is loaded. It works as long as you have your template filenames and variable names consistent However, when switching to a template engine like Smarty or Twig you should check out template inheritance. In my opinion, this is the most powerful feature and one of the main reasons to use a template engine. For smarty, I've written a little section how this could work: https://github.com/wanze/TemplateEngineSmarty#best-practices Cheers
-
I updated the module to version 1.0.1. All engines now have a setting Global template file where you can enter the filename of a template file that is used as "main template" behind the API variable. This is useful if you have a main template that contains all the markup and you need to fill certain variables per controller. Note that Smarty and Twig already support this feature with template inheritance. Also the TemplateEngineProcesswire module now supports custom suffixes for the template files. Change this setting if you'd like to name the templates different than the controller, e.g "home.tpl.php". Cheers
-
You're welcome. I don't have any experience with client side PDF creation tools. I have done some work with TCPDF in the past and now mPDF because the HTML/CSS support is better though still limited. If you need very complex layouts then maybe it is better to not use HTML at all but the native stuff from these libraries, e.g. positioning the cursor and output text/shapes/images exactly where you need it. Personally, I prefer a server-side solution because JS can be manipulated by the visitor, not sure how to deal with saving PDF files then. On the other hand, if the PDF files are always created "on the fly", why not - if enough browser support is given.
-
Thanks Can, good luck with your project The new version is now merged into the master branch, I also updated the README on GitHub. With v.1.1.1, a new config option was introduced: Creation mode This setting controls when the PDF files are generated and stored for caching purposes. The default value is still "on click", right before downloading a PDF file. Now, the PDF files can also be created when saving pages in the ProcessWire admin. This new option is preferable if the PDFs are heavy and need some time for processing - the clients won't have to wait for it. Please post any problems or questions regarding updating the module to the new version in this thread.
-
Hi Gerhard, If you grab the latest version of the module (1.1.0 is now in the master) you have several possibilites to solve this. 1) Use pages2pdf module: Do you already have a template that shows/lists the pages inside the shopping cart for a user? If so, you could create a corresponding template in /site/templates/pages2pdf/ and list the products there too. This way, the module does most of the work for you, including caching of the PDF files. What you'd need here is to delete the cached PDF file if the user adds or removes a page in the shopping cart. Simplest way of doing this is to trigger saving the shopping cart page, then the module will delete the cached PDF file. 2) Use WirePDF module: WirePDF is just wrapper around mPDF that is optimized to work with ProcessWire. If you want to create the PDF files independently from Pages2Pdf module, you may want to check out those examples: https://github.com/wanze/Pages2Pdf#wirepdf
-
Hi folks, I have refactored the module and a new version is available on the dev branch here: https://github.com/wanze/Pages2Pdf/tree/dev The module now uses mpdf in the background which has superior HTML/CSS support compared to TCPDF, but the library is slightly heavier. What's new? Creating PDFs is handled by a separate module "WirePDF". This module is just a wrapper around mpdf and you could also use it independently from Pages2Pdf as a Service to create/save/download PDF files from ProcessWire templates All the configuration options related to configure mpdf (margins, document orientation...) are now defined in the module WirePDF Some new config options in module pages2pdf. You can configure the PDF filename and the GET variable that is used when requesting a download You can download a PDF from any page The default templates have changed, with mpdf you now can use a separate stylesheet to separate CSS from HTML markup Triggering the creation/download of a PDF file is handled earlier: After the ProcessWire API is ready but before page rendering is initialized. This should improve the performance. Calling the render() method is technically no longer required, but it can still be used to output the download link. However, you could write the link by yourself if you prefer. If you'd like to test out the new version and upgrade the module: Please note down all the current settings Uninstall pages2pdf module, then replace it with the current one Install the new version Maybe add your previous settings in the WirePDF module. Some settings are no longer supported or have changed slightly If you created manual links to triggering the download in your templates, e.g. added ?pdf=1, you should change the GET variable in the module configs from 'pages2pdf' to 'pdf' Take a look at the default_templates in /site/modules/Pages2Pdf. With mpdf, it's better to separate CSS from HTML, so you can create a "styles.css" in /site/modules/templates/pages2pdf/ and define all CSS styles there. The styles are then availalble in your templates. I hope that's the most important stuff. I'm short in time today (going to a festival), so I can't support Cheers
- 343 replies
-
- 12
-
This seems currently not supported in core, see here: https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Process/ProcessPageList/ProcessPageList.module#L338 However, the method is hookable. So you could hook after this method and check for the correct template of the $page object provided as parameter. Then return your array comma separated
-
Hi ivy, You have to change the Theme of the guest user to "Ergo". If a user is not logged in, ProcessWire knows him/her as "guest". Cheers
-
I think I understand, this is a little different need. You'd have to tell the factory that your main template file is now html.php. Could you try something like this (not tested!): // In basic_page.php controller $factory = $modules->get('TemplateEngineFactory'); $basic_page = $view; // Save basic_page template which is currently behind the $view API variable $main = $factory->load('html.php'); // Load the main markup wire()->set('view', $main); // Set the context of wire view variable to be the main template $view = wire('view'); // Reassign to locally scoped $view variable - not sure if this is necessary, but I think so... $view->set('basic_page', $basic_page->render()); // Pass output of basic_page to main template If this should work, you could enable $config->prependTemplateFile an put the code in your prepended controller file, e.g. _init.php. I'll add support for that so that you can define the suffix. Actually this is supported by the Smarty and Twig additions, don't know why I did not add this for the ProcessWire engine
-
Hi pwFoo, Thanks for your interest Now you're mixing things bit up that's why it does not work. I assume that you've chosen "ProcessWire" as TemplateEngine? Then the TemplateFile class is also used to render your templates. If you are in your /templates/basic_page.php controller, then the factory has loaded for you already the corresponding template file ine /templates/views/basic_page.php. Your code loading the html.tpl.php file and echo out it's markup will not have any effect, because the factory will use the /templates/views/basic_page.php file for the output. You'd want to pass the variables to that template file with $view->set(); In the module's setting of TemplateEngineProcesswire you define where your template files are stored. When loading a file with the factory, it looks inside that folder. So I guess maybe it wil work so: // Template files are in /site/templates/views/ $chunk = $factory->load('html.php'); // File is in /site/templates/views/html.php $chunk2 = $factory->load('chunks/html.php'); // File is in /site/templates/views/chunks/html.php Now again, if you are in a controller where a corresponding template file exists, echo out will have no effect. You'd need to pass the markup to your template: // In /site/templates/basic_page.php $view->set('chunk', $chunk->render()); // In /site/templates/views/basic_page.php <p><?= $chunk ?></p> Hope I could make things clearer? Cheers
-
The disadvantage of this solution is that it requires 4 DB queries. As long as there is only a small amount of data, this should be fine. How about this: $ids = array(439,417,456,402); $result = new PageArray(); $p = wire('pages')->find("template=xx, field_x=439|417|456|402"); foreach ($ids as $id) { $result->append($p->get("field_x=$id")); } Needs only one query
-
I may be wrong, but I don't think that sub-sub-selectors are possible. You'd have to loop through your repeater pages and collect the products where the title matches.
- 1 reply
-
- 1
-
Hi Blad, You can do this with some additional logic: if( $this->input->get->sSearch ) { $q = $this->sanitizer->text($this->input->get->sSearch); if (is_numeric($q)) { $selector .= "id=$q,"; } else { $selector .= "title|body%=$q,"; } }
-
Wow fantastic website Soma, congrats to the relaunch. The animations are soo fluent!!
-
TemplateEngineTwig This module adds Twig as engine to the TemplateEngineFactory. Screenshot of the available configuration options: Project on GitHub: https://github.com/wanze/TemplateEngineTwig Project in modules directory: http://modules.processwire.com/modules/template-engine-twig/ Only Twig related things should be discussed in this thread. For common problems/features/questions about the Factory, use the TemplateEngineFactory thread.
-
TemplateEngineSmarty This module adds Smarty as engine to the TemplateEngineFactory. Screenshot of the available configuration options: Project on GitHub: https://github.com/wanze/TemplateEngineSmarty Project in modules directory: http://modules.processwire.com/modules/template-engine-smarty/ Only Smarty related things should be discussed in this thread. For common problems/features/questions about the Factory, use the TemplateEngineFactory thread. Edit: I added a section to the readme on GitHub how I think Smarty works best in combination with the TemplateEngineFactory and ProcessWire. I used this technique in a recent project and I'm very happy with it.
-
TemplateEngineFactory The main idea of this module is to support the developer separating logic from markup. This is achieved by turning ProcessWire templates into controllers which interact over a new API variable to template engines like Smarty or Twig. The TemplateEngineFactory ships with a default engine "ProcessWire" that uses the internal TemplateFile class to render the templates (some of you may already be familiar with this concept). However, the module is constructed in a way that any template engine can be used, implemented as separate modules. Please check out the readme on GitHub for more details how it works: https://github.com/wanze/TemplateEngineFactory ... or in the modules directory: http://modules.processwire.com/modules/template-engine-factory/ Implementation of Smarty: https://github.com/wanze/TemplateEngineSmarty Implementation of Twig: https://github.com/wanze/TemplateEngineTwig Implementation of Jade (by dreerr, thanks!): https://github.com/dreerr/TemplateEngineJade How does it work? A controller (aka ProcessWire template) can have an associated template file which contains the markup to render. The folder where those templates are stored is configurable for each installed engine. If the Factory finds a template file with the same name as the controller, an instance to access the template is provided with a new API variable (called "view" by default). Over this API variable, you can set the dynamic variables that should be rendered. Hopefully the following example makes things clearer: // In controller file: /site/templates/home.php if ($input->post->form) { // Do some processing, send mail, save data... $session->redirect('./'); } // Pass variable to the template $view->set('foo', 'bar'); $view->set('show_nav', true); $view->set('nav_pages', $pages->get('/')->children()); As you can see, there is no markup echoed out. The corresponding template file is responsible for this task: // In template file: /site/templates/view/home.php <h1><?= $page->title ?></h1> <p>Foo: <?= $foo ?></p> <?php if ($show_nav): ?> <ul> <?php foreach ($nav_pages as $p): ?> <li><a href="<?= $p->url ?>"><?= $p->title ?></a></li> <?php endforeach; ?> </ul> <?php endif; ?> In the example above, "ProcessWire" is used as engine. If Smarty is the active template engine, the corresponding template file could look like this: // In template file: /site/templates/smarty/home.tpl <h1>{$page->title}</h1> <p>Foo: {$foo}</p> {if $show_nav} <ul> {foreach $nav_pages as $p} <li><a href="{$p->url}">{$p->title}</a></li> {/foreach} </ul> {/if} Note that the API variable acts as a gateway which connects you to the activated template engine. We can switch the engine behind without changing the controller logic! (I know that this is probably not a very common need, but it's a cool thing anyway ) For further information, please check out the readmes on GitHub. Please ask questions if anything makes no sense - sometimes it's hard to get my explanations Cheers
-
WillyC is right Another example that does not work with magic getters: $arr = array(1,2,3); $session->arr = $arr; // Does not work! echo $session->arr[1]; // To echo out array elements, do this $arr = $session->arr; echo $arr[1];
-
Specify the field you want to filter from the page as subfiled, e.g. hue.title~=$q
-
You forgot to foreach loop over the gigs of today. $heute is a PageArray, not a Page. Cheers Edit: Marcus won the race
-
Thanks Can, glad it works for you I'm currently rewriting the module and will switch the pdf engine behind to mpdf which seems to have much better support for html. @Bacelo There are no stupid questions
-
I was having a similair issue, see here: https://github.com/ryancramerdesign/ProcessWire/issues/409 But ryan fixed it and the solution worked for me.
-
Hi Adrian, Thanks for your suggestion, it makes totally sense - will update the module later this week. The reason I've chosen to add this setting is that the color has to be set with javascript (jqplot) so it can't be controlled with CSS. The bar graph colors could be changed with CSS, but of course the colors should match by default! Cheers
-
Hi Bacelo, Thanks and sorry for my late reply. This could be done pretty easy with some custom coding. How would you integrate this into the module? I want to optimize and rewrite the module in the coming weeks. Cheers