Jump to content

Neo

Members
  • Posts

    112
  • Joined

  • Last visited

Everything posted by Neo

  1. I have a site with a blog section (every blog post is a page), which I don't want to populate in the list view via the ordinary pagination. Instead, I have written a bit of JS to load the blog posts after each other: in this case always 2 blog posts by the click of a button via $.getJSON(). So I use a JSON file to get my page data from Processwire. On the ProcessWire site, I have written the following code on the top of my blog.php list view template: <?php $json = array(); $posts = wire('pages')->find('template=blog-post, sort=-blog_date'); foreach($posts as $post) { $json[] = array( 'link' => $post->url, 'date' => $post->blog_date, 'title' => $post->title //'preview' => substr($post->body, 0, 250) ); } file_put_contents('posts.json', json_encode($json)); So this basically creates the posts.json file in http://example.com/My_Project/site/templates/posts.json every time the template is accessed. This works, the data is populated in the view. However, I am not sure if this is the best way to approach this considering performance as the json file is created every time the page is requested. Would appreciate your advice.
  2. I have saved a couple of string phrases inside my static code that need to be translated. I saved those in the central site translation files. What you would normally do then in the page-context is the following, which works without problems: <?php echo __("This is my string."); ?> Now, I have a situation, where I need one of those strings in a functions-file that is included in one of my templates. As this is not the normal page-context, all ProcessWire objects need to be wrapped in the wire() function. I tried to call my translatable strings in different ways, but without success: $translation = __("My string"); // will always show the string in the default language $translation = wire('this')->_("My string"); // call to member function on null Would appreciate your advice. UPDATE: I got it working now with the normal way that you would use in the page-context. Not sure what the problem was
  3. Thanks Horst, that sounds like a good solution. I actually thought about using the pbckcode plugin and configuring the language classes via config.js in CKEditors plugin folder, because the CSS classes are then automatically added to the <pre> tag via the back-end. The problem is that the changes in config.js are not reflected in the back-end. Already tried to delete the cache and refreshed all modules without success. You could then configure highlight.js to select a custom code container instead of using <pre><code>, e.g.: $('pre').each(function(i, block) { hljs.highlightBlock(block); }); Honestly, I thought there might be an easier solution to directly configure CKEditor via the back-end and also allow other tags (<code> etc.). Update: In this case the plugin configuration has to be placed in config-body.js to be reflected.
  4. I need to display some code snippets via the body field (text area) on the front-end using highlight.js, which requires the following output format: <pre><code class="languageClass hljs"> // Code goes here </code></pre> My frontend-styling is in place, but the problem is that CKEditor filters the markup and simply wraps everything in <pre> when using the "formatted" option. I had a look at the pbckcode plugin, which I installed, but the generated markup does not include the <code>-element with the required language classes in CSS. It simply adds classes to <pre> and is not meant to work with highlight.js out-of-the-box according to the author. I am not sure what is the best option to get this working and also to allow other tags in CKeditor (for example <code>, <small> etc.). Would appreciate your advice.
  5. I had to change the default language check to get it working: foreach($all_options as $option) { $title = $user->language->name == 'default' ? $option->title : $option->get("title$language"); echo "<li><a href='#' class='filter-category' data-filter='.$title'>$title</a></li>"."\n"; } ?> Don't know why $language->isDefault() always fails...
  6. That will always display the foreign language version, also for the default language.
  7. I have a select options field, which needs to be translated. The translation works fine as long as you echo the available options page-specific. Now, according to the documentation, when you need to display all possible options (independently of any page), you would do something like this: <?php // Get all category options $field = $fields->get('project_category'); $all_options = $field->type->getOptions($field); foreach($all_options as $option) { echo "<option value='.{$option->title}'>{$option->title}</option>"."\n"; } ?> The problem is that this does not pass the translated language values for each option. It will display always in the default language. Any idea how to get the translations in this situation?
  8. Looks like other users experienced the same issue... Does anyone know how to fix this?
  9. After deleting a language pair in ProcessWire 3.0.32 Latest (NS) , I am getting the following error: PagePathHistory::getPage() - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'language_id' in 'field list' (WireLog) Not sure if this is related to this reported issue.
  10. I have a site that was developed on ProcessWire 3 using the "beginner profile" with direct output. Requirements got changed during development and the site now needs to be multi-language. For that I installed the 4 available language modules in the backend: - Language Support (Fields, Page Names, Tabs) I then added the language switcher from the multi-language profile from _main.php to _head.php: <!-- language switcher / navigation --> <ul class='languages'><?php foreach($languages as $language) { if(!$page->viewable($language)) continue; // is page viewable in this language? if($language->id == $user->language->id) { echo "<li class='current'>"; } else { echo "<li>"; } $url = $page->localUrl($language); $hreflang = $homepage->getLanguageValue($language, 'name'); echo "<a hreflang='$hreflang' href='$url'>$language->title</a></li>"; } ?></ul> Unfortunately, that throws the following error: Error: Call to a member function getLanguageValue() on null I assume that the function getLanguageValue() is not available, although all available modules have been installed. Any idea how to fix this?
  11. What I really like about PW is the abstraction of data-handling; no messing around with database modelling, which obviously comes with a downside as well: You should do it the PW way. However, the clean API is great to access and manipulate your data if you compare this with the messy approach of other frameworks. Composer integration will be a big step forward. Does anyone know when we can expect a stable version of PW 3?
  12. There have been some interesting discussions before how to use Processwire for application development; i.e. the typical user login/logout scenario with a set of different roles and related capabilities. The question I was asking myself in the last couple of days while skipping through the Laravel documentation: Can Processwire fully replace an application framework like Laravel? Some aspects have been discussed to some extent some time ago in 2012. Would be interesting to know if in 2016 any developer in the community has completely replaced a "traditional application framework" with Processwire.
  13. I could not find a related post to this issue: I am dealing with the development of a banner advertising solution for a website, i.e. the website will show different rotating banners at different positions. A convenient way would be to use the repeater field. Not sure if it would be better to work with pages due to the possible size of the website (performance limitations ?!?). Now, the idea is to keep a specific banner within this repeater published for a specific time, e.g. 1 week, 1 month, 3 months. Once a banner has been added to the repeater and the publishing time has been selected, publication time is counted and the banner is automatically "unpublished", but not deleted after this time. Would appreciate your advice if this is possible.
  14. @RobinS @LostKobrakai Haven't thought about that possibility, which makes perfectly sense and would be easier to implement. Thanks.
  15. @kongondo In the mentioned post it looks like they added PayPal manually to a custom form and did not use the Form Builder. So the question would be how to hook into the Form Builder events, i.e. just before form submission. Unfortunately, PayPal does not operate in many countries in Latin America. The example PHP code to process payments via the MercadoPago API looks like this: <?php require_once ('mercadopago.php'); $mp = new MP('CLIENT_ID', 'CLIENT_SECRET'); $preference_data = array( "items" => array( array( "title" => "Multicolor kite", "quantity" => 1, "currency_id" => "ARS", // Available currencies at: https://api.mercadopago.com/currencies "unit_price" => 10.00 ) ) ); $preference = $mp->create_preference($preference_data); ?> <!DOCTYPE html> <html> <head> <title>Pay</title> </head> <body> <a href="<?php echo $preference['response']['init_point']; ?>">Pay</a> </body> </html>
  16. Thanks for your detailed answer, cstevensjr. Would be great to know if someone has implemented payments via the Form Builder; i.e. the form only submits after successful payment.
  17. I am currently considering the ProcessWire Form Builder for a project that requires a front-end form, which visitors can use to post new content to the site. Every form post should be saved as an unpublished page that can be reviewed by the admin, who can then later publish the page. Once the form has been submitted, an email-notification should also be sent to the admin. Ideally, the front-end form can only be submitted after a fixed payment has been made, ideally via MercadoPago API, which is very popular in Latin America. Unfortunately, you cannot test the module before purchase, so that's why I have a couple of questions: - Can form posts be saved to unpublished pages and an email-notification be sent at the same time? - Can payments be integrated into the form? I have built a course directory with ProcessWire once with a similiar specification (without payment), but coded the form manually and used the PW API to create the unpublished pages, which was Ok. If there is not too much customization required, I thought it might be a bit more convenient to use this module and facilitate back-end handling. Would appreciate your advice.
  18. Thanks for your response, AndZyk. I excluded the "portfolio" page from the menu using the selector-option in the SimpleNavigation-Module. I installed the fork you recommended and tried to exclude the page via the template-name: template=portfolio-list However, I had to delete the browser cache several times until it worked. But it seems to work now.
  19. I am sure this issue came up before. Unfortunately, I was not able to find it via the search function or Google. I have a parent page ("portfolio") that has many children ("portfolio-item"). I am using the XML Sitemap module to generate a sitemap: "The module ignores any hidden pages and their children, assuming that since you don't want these to be visible on the site then you don't want them to be found via search engines either." The parent needs to be excluded from the menu and the sitemap (Status - Hidden: Excluded from lists and searches), but the children pages should still show up and be listed in the sitemap. Any idea how to implement this?
  20. I am currently planning an e-commerce project for 300 products in 7 categories and would love to implement this with ProcessWire, which I have never used for e-commerce before. The only serious e-commerce module available at the moment seems to be Padloper (please correct me if the are other options). One of the requirements of this project is a currency switcher (British Pounds / Euros) for the same language (English). Furthermore, the site needs to have the possibility to add other languages and local currencies in the future. Is this doable with Padloper?
  21. Thanks for your repsonses. "if ( $language->isDefault() ) $hreflang = 'en';" will do it. @Sérgio: The $homepage variable would break the code.
  22. In order to generate dynamic hreflang tags, I use the following code: <?php // handle output of 'hreflang' link tags for multi-language // this is good to do for SEO in helping search engines understand // what languages your site is presented in foreach($languages as $language) { // if this page is not viewable in the language, skip it if(!$page->viewable($language)) continue; // get the http URL for this page in the given language $url = $page->localHttpUrl($language); // hreflang code for language uses language name from homepage $hreflang = $pages->get('/')->getLanguageValue($language, 'name'); // output the <link> tag: note that this assumes your language names are the same as required by hreflang. echo "\n\t<link rel='alternate' hreflang='$hreflang' href='$url' />"; } ?> The site is based on 2 languages: English (default) and Spanish. The default language does not have a language segment, Spanish uses "es". The problem with the above code is that hreflang will logically display nothing for the default, but should ideally show "en". Is this possible or is there a different way to access the multi-language URLs instead of looping through an array?
  23. Thanks for your response. I save the language switcher in a variable, which correctly displays when you echo it: <!-- language switcher / navigation --> <?php $langSwitch = ""; $langSwitch .="<li class=\"has-dropdown\"><a href=\"#\">Language</a><ul class=\"dropdown\">"; foreach($languages as $language) { if(!$page->viewable($language)) continue; // is page viewable in this language? if($language->id == $user->language->id) { $langSwitch .="<li class=\"current\">"; } else { $langSwitch .="<li>"; } $url = $page->localUrl($language); $hreflang = $pages->get('/')->getLanguageValue($language, 'name'); $langSwitch .="<a hreflang=\"$hreflang\" href=\"$url\">$language->title</a></li>"; } $langSwitch .="</ul></li>"; ?> However, I cannot get it display within the menu options array, which will literally print {$langSwitch}: 'outer_tpl' => '<ul class="right">||{$langSwitch}</ul>', Any idea?
  24. I have a Menu that is generated using the "Markup Simple Navigation" module: <?php // Echo Header Navigation Menu $headerMenu = $modules->get("MarkupSimpleNavigation"); // load the module $options = array( // Show HOME in menu 'show_root' => false, // Current class 'current_class' => 'active', // Show parent class as active 'parent_class' => 'active', // Top level ul 'outer_tpl' => '<ul class="right">||</ul>', // set the max level rendered 'max_levels' => 1, ); echo $headerMenu->render($options); // render Header menu ?> I would like to add a language switcher as an li-element to the unordered list of the menu with the following markup: <li class="has-dropdown"> <a href="#">Right Button Dropdown</a> <ul class="dropdown"> <li><a href="#">First link in dropdown</a></li> <li class="active"><a href="#">Active link in dropdown</a></li> </ul> </li> My language switcher is generated with the following: <!-- language switcher / navigation --> <li class="has-dropdown"> <a href="#">Right Button Dropdown</a> <ul class="dropdown"><?php foreach($languages as $language) { if(!$page->viewable($language)) continue; // is page viewable in this language? if($language->id == $user->language->id) { echo "<li class='active'>"; } else { echo "<li>"; } $url = $page->localUrl($language); $hreflang = $pages->get('/')->getLanguageValue($language, 'name'); echo "<a hreflang='$hreflang' href='$url'>$language->title</a></li>"; } ?></ul> </li> Would appreciate your advice how to add this to the option array of the menu.
×
×
  • Create New...