Jump to content

dotnetic

Members
  • Posts

    1,032
  • Joined

  • Last visited

  • Days Won

    15

Everything posted by dotnetic

  1. @adrian @Wanze How can I make this work with TemplateEngineFactory and Smarty? Your search function tries to render a normal template file but it does not output my search page (which I selected in module settings). So I tried to modify the search function to use a partial that would be rendered, but it didn´t work either: public function search($event) { if($this->searchPage) { $request = parse_url($_SERVER['REQUEST_URI']); $path = $request["path"]; $result = trim(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $path), '/'); $term = str_replace(array('-','_','/','%20'),' ',$result); // New way of setting the value of get->q directly. // This way, this module can work out of the box with no need to modify the search.php template file $this->input->get->q = $term; // Setting the value for $options['q'] in the render is for backwards compatibility // and as a way to identify that this module is rendering the search template so the // dev can choose to output conditional content such as if(isset($options['q'])) $content .= $pages->get(27)->body; $templateFilename = $this->pages->get($this->searchPage)->template->filename; $factory = wire("modules")->get('TemplateEngineFactory'); $partial = $factory->load('search.tpl'); $event->return = $partial->render(); } Any suggestions how I can get this to work? EDIT: It seems that the Smarty File is beeing loaded but I get much undefinded index errors. The errors appear because it seems that my _init.php isn´t prepended.
  2. Found the solution by myself. Maybe this helps others. It works if you use the so called subscript syntax From the Twig docs: You can use a dot (.) to access attributes of a variable (methods or properties of a PHP object, or items of a PHP array), or the so-called "subscript" syntax ([]): So instead of using {% if page.facebook %} Just use {% if page['facebook'] %} and it works
  3. I tried to use the TemplateEngineTwig in PW 3.0.22 (devns). It did not work. Then I downloaded the latest version of twig from their website and replaced the lib folder in the modules\TemplateEngineTwig folder but I still get the same error: Error: Exception: An exception has been thrown during the rendering of a template ("Method Page::homepage does not exist or is not callable in this context") in "logspot_profile.twig" at line 20. (in K:\xampp\htdocs\logspot-pw\src\site\assets\cache\FileCompiler\site\modules\TemplateEngineTwig\TemplateEngineTwig.module line 111) Here is what I try to do: {% if page.homepage %} <a href="{{ page.homepage }}" target="_blang">Homepage</a> {% endif %} Anyone got a simple solution?
  4. The problem is that the textformatter tries to call the width function on an non-existent image. Have you tried to uncheck the option LQP? Is the error still occuring then?
  5. Take a look here https://processwire.com/talk/topic/6833-module-templateenginefactory/?p=78641 and also my comment https://processwire.com/talk/topic/6833-module-templateenginefactory/?p=122354
  6. Hi Wanze, EDIT: Found the solution by myself. Added to the bottom. I got a problem with Search and the TemplateEngineFactory (I use Smarty). If I use AJAX my search.php should return a JSON response (with correct headers), if not it should render the template. The problem is that if I have a template file search.tpl it will always be rendered even if I request with AJAX. So I renamed the template file and tried to load it on demand in search.php: if ($config->ajax) { header("Content-type: application/json"); // Set header to JSON echo $matches->toJSON(); // Output the results as JSON via the toJSON function } else{ $factory = $modules->get('TemplateEngineFactory'); $view = $factory->load('search-results.tpl'); echo $view->render(); exit; } search-results.tpl {extends file="main.tpl"} {block name="content"} <h1>{$page->title}</h1> {$content} {/block} Now my AJAX response works and the template gets rendered BUT it seems that variables assignments which I do in the _init.php are not executed. For example I set the browsers title and the main menu structure there, but the menu or the title do not get rendered, although _init.php is prepended because if I do an echo there, it displays on the page. I hope somebody can help me with this problem. EDIT: Solution is to just exit at the end of the AJAX clause, so the template does not get rendered if ($config->ajax) { header("Content-type: application/json"); // Set header to JSON echo $matches->toJSON(); // Output the results as JSON via the toJSON function exit; }
  7. The problem with your approach is, that it only requests the data once and ProcessWire returns all pages instead of those who match the query string. This could be a problem on very dynamic sites, where the content changes often. Here is my solution which solves this: Modify the standard search.php and add if ($config->ajax) { header("Content-type: application/json"); // Set header to JSON echo $matches->toJSON(); // Output the results as JSON via the toJSON function } so the whole file reads <?php namespace ProcessWire; // look for a GET variable named 'q' and sanitize it $q = $sanitizer->text($input->get->q); // did $q have anything in it? if ($q) { // Send our sanitized query 'q' variable to the whitelist where it will be // picked up and echoed in the search box by _main.php file. Now we could just use // another variable initialized in _init.php for this, but it's a best practice // to use this whitelist since it can be read by other modules. That becomes // valuable when it comes to things like pagination. $input->whitelist('q', $q); // Sanitize for placement within a selector string. This is important for any // values that you plan to bundle in a selector string like we are doing here. $q = $sanitizer->selectorValue($q); // Search the title and body fields for our query text. // Limit the results to 50 pages. $selector = "title|body%=$q, limit=50"; // If user has access to admin pages, lets exclude them from the search results. // Note that 2 is the ID of the admin page, so this excludes all results that have // that page as one of the parents/ancestors. This isn't necessary if the user // doesn't have access to view admin pages. So it's not technically necessary to // have this here, but we thought it might be a good way to introduce has_parent. if ($user->isLoggedin()) $selector .= ", has_parent!=2"; // Find pages that match the selector $matches = $pages->find($selector); $cnt = $matches->count; // did we find any matches? if ($cnt) { // yes we did: output a headline indicating how many were found. // note how we handle singular vs. plural for multi-language, with the _n() function $content = "<h2>" . sprintf(_n('Found %d page', 'Found %d pages', $cnt), $cnt) . "</h2>"; // we'll use our renderNav function (in _func.php) to render the navigation $content .= renderNav($matches); } else { // we didn't find any $content = "<h2>" . __('Sorry, no results were found.') . "</h2>"; } if ($config->ajax) { header("Content-type: application/json"); // Set header to JSON echo $matches->toJSON(); // Output the results as JSON via the toJSON function } } else { // no search terms provided $content = "<h2>" . __('Please enter a search term in the search box (upper right corner)') . "</h2>"; } Then call typeahead with the following options: $.typeahead({ input: '#q', order: 'desc', hint: false, minLength: 3, //cache: false, accent: true, display: ['title'], // Search objects by the title-key backdropOnFocus: true, dynamic: true, backdrop: { "opacity": 1, "background-color": "#fff" }, href: "{{url}}", emptyTemplate: "No results for {{query}}", searchOnFocus: true, cancelButton: false, debug: true, source: { //url: actionURL // Ajax request to get JSON from the action url ajax: { method: "GET", url: actionURL, data: { q: '{{query}}' }, } }, callback: { onHideLayout: function (node, query) { $('#searchform').hide(); console.log('hide search'); } } }); The important parts are "dynamic:true" and the "source" configuration so the query string is beeing sent. Now you have a nice AJAX search. EDIT: If you also want to find the query string in other fields than the title make sure you add filter: false to the config of typeahead.
  8. Finally better editing of environment variables like path in Windows 10 Build 1511. Nice :)https://t.co/vwfxBsLY2J

  9. Finally better editing of environment variables like path in Windows 10 Build 1511. Nice :) https://t.co/vwfxBsLY2J

  10. @kongondo Thank you for clarification. It works in my multilingual site if I use it with an ID: $menu->render($pages->get(1126), $options) But now another problem occurs. There are several empty A tags between my menu items with this configuration: $menu = $modules->get('MarkupMenuBuilder'); $defaultOptions = array( 'wrapper_list_type' => 'div',//ul, ol, nav, div, etc. 'list_type' => 'a',//li, a, span, etc. 'menu_css_id' => '', 'menu_css_class' => '', 'current_css_id' => 'active', 'divider' => '»',// e.g. Home >> About Us >> Leadership //prepend home page at the as topmost item even if it isn't part of the breadcrumb 'prepend_home' => 1,//=> 0=no;1=yes 'default_title' => 1,//0=show saved titles;1=show actual/current titles 'include_children' => 0,//show 'natural' MB non-native descendant items as part of navigation 'b_max_level' => 1,//how deep to fetch 'include_children' ); $view->set('mainmenu', $menu->render($pages->get(1126), $defaultOptions)); $view-set is for assigning the menu to my smarty variable, in case you wonder. The output looks like <div> <a> </a><a href="/">Start</a> <a> </a><a href="/de/termine/">Termine</a> <a> </a><a href="/de/produkte/">Produkte</a> <a> </a><a href="/de/haendler/">Händler</a> <a> </a><a href="/de/ueber-uns/">Über uns</a> <a> </a><a href="/de/news/">News</a> </div>
  11. Hi @kongondo. It doesn´t even work in PW 2.7.3. When I dump ($menu->render('mainmenu', $options)) to my Tracy Debug Bar in my main language, I see the generated code for the menu. As soon as I switch the language the output of the dump is false, the menu does not seem to exist. EDIT: When using standard processwire API in my smarty template, the titles are fine. {foreach $homepage->and($homepage->children) as $p} <li {if $p->id == $page->id} class="active"{/if}><a href="{$p->url}">{$p->title}</a></li> {/foreach}
  12. Hi @kongondo, I try to use this module with a multilanguage site with ProcessWire 3.0.15 (devns), but when I switch the language the menu does not show up. It only appears on the default language (german). Here is the code I used: $menu = $modules->get('MarkupMenuBuilder'); $options = array( 'default_title' => 1,//0=show saved titles;1=show actual/current titles ); $menu->render('mainmenu', $options)); The titles of the pages that are in the menu are translated in ProcessWire. Any suggestions what I can do to get it running?
  13. Please mark your post as answered, as it would help others to see directly, that no further action is required.
  14. EDIT: I got it working now. Seems like PW 3 has cached (compiled) my module and used the old version, instead of my changed script. Don´t know if this is really the case, but it works now. Thank you for all suggestions. Another EDIT: Now I know, where the error and endless loading came from. It was the line 'permission' => array(""), in the getModuleInfo function. After removing it and deinstalling and installing the module again, everything works fine. How can I prevent, that PW3 caches my module, so I can see changes immediately when I change the code or is the caching (compiling) intended?
  15. I try to replace the string "P. Jentschura" with "P. Jentschura" via a Textformatter for the body field. When I load the page, it loads infinitely, which is caused by the Textformatter. What am I doing wrong? Here is my code: <?php /** * Textformatter P. Jentschura (1.0.0) * Sorgt dafr, dass der Name P. Jentschura mit einem geschtztem Leerzeichen versehen wird. * * @author Jens Martsch * * ProcessWire 2.x * Copyright (C) 2011 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com * */ class TextformatterJentschura extends Textformatter { public static function getModuleInfo() { return array( 'title' => "Textformatter P. Jentschura", 'version' => "1.0.1", 'summary' => "Sorgt dafür, dass der Name P. Jentschura mit einem geschütztem Leerzeichen versehen wird.", 'author' => "Jens Martsch", 'href' => "", 'permission' => array(""), 'autoload' => false, 'singular' => true, 'permanent' => false, 'requires' => array("PHP>=5.4.0", "ProcessWire>=2.5.3", ""), 'installs' => array(""), ); } public function formatValue(Page $page, Field $field, &$value) { if (strpos($value, "P. Jentschura") === false) return; $value = preg_replace_callback('/P\. Jentschura/', array($this,"replace"), $value); } function replace($match){ return str_replace($match, 'P. Jentschura', $match); } }
  16. I got a question for translating the strings in the template files, as I have a multilanguage site and use the Smarty Engine. The ProcessWire Language Translator module does not list the files in the folder /site/templates/views nor I can select and translate those files with the "translate file" button. I only see .php files under /site/templates/. My template files got the .html extension but with .tpl extension it also doesn´t work. What do I have to do to translate my template files? Here is my actual file /site/templates/views/products.html {extends file="main.html"} {block name="content"} <h1>Check out the following products</h1> <span>{__('Dieser String muss in alle Sprachen übersetzt werden')}</span> <ul> {foreach $products as $p} <li><a href="{$p->url}">{$p->title}</a></li> {/foreach} </ul> {/block} {block name="javascript"} <script type="javascript" src="{$config->urls->templates}js/products.js"></script> {/block}
  17. There is a fix needed in the .htaccess file to allow services like Let´s encrypt to use the webroot authentication method. I created a pull request for this https://github.com/ryancramerdesign/ProcessWire/pull/1751
  18. „This is Native!!! - Mobile apps development battle #tech2016“ von @Doff3n auf @LinkedIn https://t.co/YBTLFDez5U

  19. I am using the api as suggested in somas gist´s but I want to have multiple checkboxes that don´t have own div´s but instead are together in one div so I can style them as a button-group. The markup I want is: <fieldset> <legend>Ich möchte</legend> <div class="button-group"> <input id="checkbox1" type="checkbox" name="Neue Kunden gewinnen" value="Ja"> <label class="button" for="checkbox1">neue Kunden gewinnen</label> <input id="checkbox2" type="checkbox" name="Meine Kunden halten" value="Ja"> <label class="button" for="checkbox2">Kunden halten</label> <input id="checkbox3" type="checkbox" name="Kunden zurückgewinnen" value="Ja"> <label class="button" for="checkbox3">Kunden zurückgewinnen</label> </div> </fieldset> I should mention, that these are not the only fields in the form. Here is a screenshot of what I try to accomplish. How can I do that? InputFieldWrapper to the rescue?! But how?
  20. Hi Mr. Rockettman, is there an estimate when this module will be ready for production? I would love to use it for my projects. It looks very promising.
  21. Diese Bäckerei verwendet Cookies. Falls Sie eintreten, merken wir uns ihr Gesicht und sie müssen einen Cookie essen. #cookies

  22. This module still works with PW 2.7.1 and it´s a great one. I think it should be in core.
  23. @teppo You´re right. Thanks for pointing this out. So I added $config->sessionFingerprint = 2; to site/config.php. Option 2 Fingerprints only the remote IP and not the user-agent
  24. To prevent being logged out when dev-tools is open add: $config->sessionFingerprint = 2; in your site/config.php (my PW version = 2.7) No more logouts. Problem solved. EDIT: Modified the instructions as teppo pointed out.
  25. #Foundation6 is here. Now I am integrating it into an existing project. Wondering how it works out.https://t.co/BkFaQYVDl3

×
×
  • Create New...