Jump to content

Tyssen

Members
  • Content Count

    253
  • Joined

  • Last visited

Community Reputation

35 Excellent

About Tyssen

  • Rank
    Distinguished Member

Contact Methods

  • Website URL
    https://www.tyssendesign.com.au/

Profile Information

  • Gender
    Male
  • Location
    Brisbane, Australia

Recent Profile Visitors

4,518 profile views
  1. Figured it out in the end. Coded above would work fine, but I had other conditionals in place which were preventing parts of it from running.
  2. I'm working with an XML feed which provides image URLs that I want to save to an images field in a repeater. So far I have this: foreach($page->goodreads as $goodreads) : $xml_string = $cache->get($goodreads->isbn, 3600, function() use($goodreads_api, $goodreads) { return curl_get_contents('https://www.goodreads.com/search/index.xml?key='.$goodreads_api.'&q='.$goodreads->isbn); }); $book_xml = new SimpleXMLElement($xml_string); foreach ($book_xml->search->results->work as $book) : $goodreads->of(false); $goodreads->images->add($book->best_book->image_url); $goodreads->save(); $goodreads->of(true); endforeach; endforeach; I've tested that $book->best_book->image_url does actually return a value and have also tested the above with a hard-coded image URL but in both cases, no image is saved. What am I missing?
  3. I have a page that contains a single ProFields table field and I want to display the contents of the table on the front end and then for logged in users, they can edit certain columns in the table. What I have at the moment is $out = '<form action="'.$page->url.'" method="post" > <table class="table"> <tbody>'; $count = 1; foreach($page->fieldName as $row) : $out .= ' <tr> <td><input type="checkbox" name="fieldName_'.$count.'_columnName"></td> </tr>'; if($input->post->submit) : $page->of(false); $page->set('fieldName_'.$count.'_columnName', $sanitizer->text($input->post->{fieldName_'.$count.'_columnName})); $page->save(); endif; $count++; endforeach; $out .= ' </tbody> </table> <button class="button" type="submit">Save</button> </form>'; The two problems I have are: I get an error trying from $sanitizer->text($input->post->{fieldName_'.$count.'_columnName}), not sure how to make that dynamic. If I change the above to just a static value, e.g. $page->set('fieldName_1_columnName', 'Testing') and save the form, it's not saving the values to the database. Where am I going wrong?
  4. Actually never mind, set it as a variable in _init.php and then call it in the twig template.
  5. Another question: in Twig how would you call modules like AIOM where in PHP it'd be <?=AIOM:CSS(array())?> or <?=AIOM:JS(array())?> ?
  6. I've obviously missed something, because I'm getting Call to a member function render() on null from _main.php. My templates are… _init.php <?php $twig_main_dir = $config->paths->site . 'templates/views'; $twig_loader = new \Twig\Loader\FilesystemLoader($twig_main_dir); $twig_env = new \Twig\Environment( $twig_loader, [ 'cache' => $config->paths->cache . 'twig', 'debug' => $config->debug, 'auto_reload' => $config->debug, 'strict_variables' => false, 'autoescape' => true, ] ); if ($config->debug) { $twig_env->addExtension(new \Twig\Extension\DebugExtension()); } foreach (['page', 'pages', 'config', 'user', 'languages', 'sanitizer'] as $variable) { $twig_env->addGlobal($variable, wire($variable)); }; $twig_env->addGlobal('homepage', $pages->get('/')); $twig_env->addGlobal('settings', $pages->get('/site-settings/')); $variables = []; _main.php <?php $template_file = 'views/' . $page->template->name . '.twig'; $twig_template = file_exists($twig_main_dir . '/' . $template_file) ? $template_file : 'views/basic-page.twig'; echo $config->twig_env->render($twig_template, $variables); My .twig templates are set up as yours are and my PW .php templates are just blank at the moment.
  7. So I think I got it. I had to add this to package.json under globs. "critical": [ { "url": "", "template": "home" }, { "url": "url-using-this-template", "template": "basic-page" }, { "url": "blog", "template": "blog" }, { "url": "blog/blog-post-url", "template": "blog-item" }, { "url": "contact", "template": "contact" } ],
  8. I'm working on a site that uses the front-end tooling set-up from https://github.com/nystudio107/craft It uses package.json for defining all the Gulp plugins and paths as described in https://nystudio107.com/blog/a-better-package-json-for-the-frontend I've been able to convert it for use with my Processwire project but I'm a bit confused about how the Critical CSS part works and how to map URLs to templates. I've also found https://processwire-recipes.com/recipes/inline-critical-css/ which uses Grunt but again, it's not clear to me how it handles all the templates. Has anyone got a similar set up working and would you be able to share your package.json or gulpfile?
  9. Every page is going to use the repeater matrix but only the home page is going to need to have the repeater as well so I was trying to find a solution that would keep the repeater option out of the matrix field, but I guess it's not that big a deal really, so I'll go with that.
  10. Thanks guys, I think I have it working, but I'm waiting for feedback from the content editor because I'm unsure if the output is as expected.
  11. I have two fields on a page, one a normal repeater and the other a repeater matrix. What I want to be able to do is allow the content editors to choose to insert the content from the normal repeater field in between other content in the repeater matrix field. I thought I could insert some text into the repeater matrix and then do a conditional in my templates to check for that string and insert the other field's output there. My template looks like this at the moment: home.php $inserted = 'Data from the normal repeater field created with a foreach loop'; $page->render('repeater_matrix_field'); repeater_matrix_field.php foreach($value as $item) : echo $item->render(); endforeach; matrix_body.php if($page->heading=='Replace this') : echo $inserted; else: echo '<h2>'.$page->heading.'</h2>'; endif; I don't get any output I guess because the $inserted variable doesn't get passed from home.php to the other templates. So is there a way to do that, or is there a better way to achieve what I'm trying to do?
  12. I then get an error on the next line. And in testing whether $randomPage was actually returning anything by just outputting the page title, I'm getting instead of repeater items randomised from Pages A–E.
  13. With $randomPage = $pages->get("id=1049|1053|1055|1059|1152")->findRandom(1); or getRandom(1) I get
×
×
  • Create New...