Jump to content

abdus

Members
  • Posts

    743
  • Joined

  • Last visited

  • Days Won

    42

Everything posted by abdus

  1. I refreshed the file list, and added translations for home.php, but nothing changes. Language page File translations page Translating markup/home.php Below is my home template file and its markup file. /* home.php */ <?php namespace ProcessWire; ... .. . include("markup/home.php"); /* markup/home.php */ <?php namespace ProcessWire; ?> <!doctype html> <html lang="<?php echo _x('en', 'HTML language code'); ?>"> ... .. . </html> // html output is wrong without _main.php <!doctype html> <html lang="en"> // correct with _main.php <!doctype html> <html lang="tr">
  2. I'm trying to build a multilanguage website with Turkish as main and English as alternative language. I replaced hardcoded strings in template files and used built-in translation tools to translate template files. I'm using the functions ProcessWire provides: // using __() <?= __("There are no products to display.") ?> // or _x() <html lang="<?= echo _x('en', 'HTML language code'); ?>"> // Both works when I use _main.php When I disable auto including _main.php from config.php file, and move or rename _main.php to something else or use another file (other than _main.php that comes with site-languages profile) for template specific markups, say markup/products.php like below, translations stop working. // config.php, disabled auto append // $config->appendTemplateFile = '_main.php'; // home.php include_once("./_main.php"); wireIncludeFile("./_main.php"); // TRANSLATION WORKS include_once("./_home.php"); // DOESNT WORK wireIncludeFile("markup/_main.php"); include_once("markup/_main.php"); // DOESNT WORK // NOTE: home.php and main.php has the same content, same permissions, same ownership I debugged the issue, and the reason, as ridiculous as it sounds, originates from using file other than _main.php. I searched the forums, google, but this seems like a unique issue. Is there anything I'm missing and how can I fix this, because I can't think of anything else after hours lost trying to find the underlying cause? Thanks in advance.
  3. That's a nice one. I'm learning the API, so I want to utilize its core functions more, as they have certain advantages like I don't know the internals of output buffering though, I'm new to PHP. Thanks a lot.
  4. I solved it. Thanks to Macrura's recommendation, I was able to render the page without losing context. The code is simplified into this: // home.php, check if parent has children: if true, render partial, full page otherwise if(! hasChildren) // render partially $template_file = $parent->template->filename; wireIncludeFile($template_file, array('renderPartial' => true)); ... ... // Using renderPartial, which you can access by itself // as $renderPartial in the template file associated with the page // contact.php // Render partial if (isset($renderPartial) && $renderPartial) { wireIncludeFile("partials/_contact_form.php"); } else { // render the whole page ... ... // Append contact form to the end of content $content .= wireRenderFile("partials/_contact_form.php"); // Call main template include("_main.php"); } // Everything renders fine, can access $config->scripts->foot|head just fine. For reference: wireRenderFile wireIncludeFile
  5. Huh, that's weird. I couldnt find it either http://apigen.juzna.cz/doc/ryancramerdesign/ProcessWire/class-Page.html I think that parameter is left from when I was playing with wireIncludeFile/wireRenderFile What's more weird is that it works. I can access the given parameter perfectly fine on its template file. // contact.php, one of the sections in homepage // If partial render is not requested render the whole page if (isset($options['renderPartial']) == false) { // Append contact form to the end of content $content .= $page->render("partials/_contact_form.php"); // Call main template include("_main.php"); } // If only the contact form is requested, return it alone elseif (isset($options['renderPartial']) == true && isset($options['renderPartial']) == true) { include("partials/_contact_form.php"); } I employed wireIncludeFile/wireRenderFile somewhere else for creating email markup, but let me try using it here too.
  6. Hi, I'm working on a homepage template where I loop over some pages, check if they have children, and print their children; if not, print the page itself where I employ page->render function. Inside template files of these parent pages, I use $config->scripts->[foot|head]->add() to enqueue scripts and and when creating markup I print the contents of these FilenameArrays using simple foreach loops. With parents that have children, which don't require rendering a part of page (as opposed to rendering whole html document), there's no problem using $config->scripts, using PHPStorm's debugger I can track the scripts up until where the execution comes to parents with no children. When used with $parentPage->render(array('renderPartial' => true)) these pages get rendered from beginning using their own context, completely ignoring the previous one, and resulting in flushing $config->scripts->[foot|head].After many hours of fiddling with here and there, I'm lost and I don't know how else I can tackle with this problem. The question I have is if there's a way to manually render a page without losing the context? Or, in which variable I can store FilenameArrays? // The code I have can be paraphrased as // Homepage sections foreach $section as $parent if $parent->hasChildren foreach $children as $child renderChild() else $parent->render(partial=true) // In each parent's template $config->scripts->head->add("head.js") $config->scripts->foot->add("foot.js") // both foot and head initialized at _init.php // After using $parent->render(partial=true) // $config->scripts gets flushed loop_over_and_write_scripts('foot') // returns nothing, $config->scripts->foot is empty Thanks in advance.
  7. I looked everywhere for that button I guess you can't pick your answer as best. Thanks!
  8. Hi, I'm working on a custom contact form and I want to create an HTML markup for email body. After tedious and long searches I've found wireRenderFile function that does exactly what I need. Pass in template file and variables to use, it returns the output. Except that it doesn't. It simply returns an empty string. I tested the same template using wireIncludeFile, it echoes the output perfectly. (I'm using the latest 2.6.16 DEV version of ProcessWire) Here's what I did: Got and processed user inputs Created a simple partial template file at templates/partials/_email.php with contents <?php if (isset($vars)): ?> <div class="meta"> From: <b><?= $vars["name"] ?></b><br> Email: <?= $vars["email"] ?><br> sent this at <?= $vars["date"] ?> </div> <hr> <div class="message"> <?= $vars["body"] ?> </div> <?php endif; ?> Prepare mail data and send it $mail = wireMail(); ... ... $bodyHTML = wireRenderFile("partials/_email.php", array( "name" => $name, "body" => $body, "email" => $email, "date" => date("r"), )); ... ... ... if ($mail->testConnection()) { $mail->sendSingle(true) ... ->bodyHTML($bodyHTML) ->send(); } The $bodyHTML variable gets an empty string from wireRenderFile function. When I replace it with wireIncludeFile $bodyHTML = wireIncludeFile("partials/_email.php", array(<data>)); The template is rendered correctly, but echoed instead of returned (it returns boolean anyway). I think I can collect the output using ob_start() and ob_get_contents(), but the code above should work correctly and I dont want to use a hack for it, yet. Thanks in advance for any help. --- EDIT: I solved it. wireRenderFile function imports given data in $vars variable as separate entities as in // Second argument is $vars $bodyHTML = wireRenderFile("partials/_email.php", array( "name" => $name, "body" => $body, "email" => $email, "date" => date("r"), )); // $vars variable is included in template file as in $name = $vars["name"] ... // etc. There's no need (can't) to access to $vars variable. I was able to output the data with this modified template file. Notice the if (isset($vars)) is removed since $vars variable doesnt exist in that context. <div class="meta"> From: <b><?= $name ?></b><br> Email: <?= $email ?><br> sent this at <?= $date ?> </div> <hr> <div class="message"> <?= $body ?> </div>
×
×
  • Create New...