Jump to content

Gazley

Members
  • Posts

    526
  • Joined

  • Last visited

Everything posted by Gazley

  1. @MuchDev There is no $config->httpUrl but I can certainly do $pages->get('/')->httpUrl and that gives me what I need. Thanks for reminding me httpUrl. I forgot all about that because I was looking at the $config options only! @adrian It certainly does give me the port. Thanks for that
  2. Hi, Is there a $config->url type of option that will return the URL below when I am running on localhost (ie: with the specified port, too) ? http://localhost:8888/ I want to do a redirect when on the live server or localhost. Thanks!
  3. @Manaus That's great! Here is my hooked method: public function hookInitTwig(HookEvent $event) { $twig = $event->arguments('twig'); $twig->addGlobal('hsaApp', wire('config')->hsaApp); $twig->addGlobal('hsaDist', wire('config')->hsaDist); $twig->addExtension(new \Twig_Extension_Debug()); } The only problem with what you have done is that you have amended the original module. When you update that module, you will lose your added code. If you add to a hooked method outside of the Twig module, your changes will be preserved.
  4. @Wanze Yep, that was it -- dump() works perfectly now!
  5. Ah, that'll explain it and will likely resolve @Manaus's issue too! Many thanks for pointing this out
  6. Just a heads-up, I've just tried to use the dump function in my own code and get: Exception: Unknown "dump" function in "_header.html.twig" at line 31. Looks like I'll have to check this further!!!
  7. Just one other thing, have you actually tried using var_dump in PHP on the value you are trying to dump? It may be that var_dump is outputting nothing natively and if so, the Twig dump function (being just a wrapper around var_dump) will likewise output nothing.
  8. You don't need the above code in the hook because, like I said earlier, it seems that the Twig module is already doing this. However, despite not needing the hook code, you have not implemented it correctly as you would need to access the $twig variable from the $event parameter. $twig = $event->arguments('twig'); Either way, remove your hook code from your _init.php file. If $config->debus is true, then I'm all out of ideas on this. Sorry.
  9. Yep, it seems that the module configures 'debug' (and therefore "dump") based on the value on config.php so, no additional setup required. You can remove the code from ___initTwig for the above reason. However, you do not add code directly to ___initTwig - you just hook ___initTwig and the code is elsewhere (see ProcessWire hooks). Next obvious question, do you have 'debug' set to true in your site/config.php file? If not, set it to true.
  10. You would have to add that code in the ___initTwig method in the Twig module. The $twig variable you create in the calling page is not connected to the template engine in any way - it's just a random, isolated variable. See my earlier post for and idea of where/how this is done:
  11. Have you configured it? From http://twig.sensiolabs.org/doc/functions/dump.html The dump function is not available by default. You must add theTwig_Extension_Debug extension explicitly when creating your Twig environment:
  12. Hi @Manaus, If you want to call your isValidUser function in your Twig template, you'll have to extend Twig by hooking the ___initTwig method in TemplateEngineTwig.module. Assuming, I've called the hook method 'hookInitTwig', you'd do something like below (not tested!!!): public function hookInitTwig(HookEvent $event) { $twig = $event->arguments('twig'); $function = new \Twig_SimpleFunction('isValidUser', function (...) { // Assuming isValidUser function is in scope ... return isValidUser(...); }); $twig->addFunction($function); } Obviously, if you don't want to add the function directly into Twig, you can evaluate your isValidUser in the ProcessWire template (Controller) and assign its result to a variable that can be referenced inside the Twig template (view).
  13. Hi, I don't know whether anyone is actively monitoring the thread for the TemplateEngineTwig.module but I have posted the following message there. Many thanks!
  14. Hi @Wanze, Many thanks for providing this fantastic module! I have just installed the module but immediately hit a problem that is not of your making in any way, but a code change in TemplateEngineTwig.module would make my life very much easier and possibly other future users of the module! Basically, I already use Twig for some TemplateFile rendering (Field level templates) using my own custom module. I've decided to use your Controller/View approach for my regular ProcessWire templates but when trying to install your module, I get the following error: "Cannot redeclare class Twig_Autoloader". Obviously, this is because my module has already loaded this class and TemplateEngineTwig.module is trying to do the same thing again. The following code change at the top of TemplateEngineTwig.module will not hurt anyone else, but will help me enormously. If you could modify the module to make this check, I'd really appreciate it! if (!class_exists('Twig_Autoloader')) { require_once(__DIR__ . '/vendor/twig/twig/lib/Twig/Autoloader.php'); } Many thanks indeed
  15. OMG, it does work! I must have assumed because there was no getter, that I couldn't access it. Thank you very much indeed
  16. Hi there, I'm hooking TemplateFile::render like so: $this->addHookAfter('TemplateFile::render', $this, 'hookRender'); In hookRender, I really need to know the filename that the template is based on. This is stored as a protected class field called 'filename' but with no getter available. Any ideas how to gain access to the filename in the circumstances I have described? Many thanks!
  17. Hi @horst - many thanks for your reply. It's a really great answer and I appreciate you taking the time to provide this information. I guess I thought some metadata, like "quality", could be accessed directly from an Image instance but as you have shown, it's easy enough to new-up an ImageSizer object. Thank you!
  18. Hi there, I'm using ImageSizerEngineIMagic and it has an overridable, default image quality value. In my application code, you can override the module's value based on a user Page field value. However, if there is no "custom" value in the page field, I'd like to be able to access the ImageSizerEngineIMagic module's default value. There is likely a very easy way to do this. If anyone could point me to it, I'd be very grateful! Many thanks.
  19. Edit: Please ignore this post - the more I play with the code, the more obvious the answer is and the more stupid this question is! Sorry Hi @horst - I don't know whether this is the correct thread to ask this question but it is connected because I danced with this lady I haven't done any cropping with PW before and have noticed the following. I add a "master" image to PW called "st_mi_18.jpg". In the backend UI, I crop the image and PW saves the copy as "st_mi_18-v1.jpg". The current use-case is that I want to save various "art-directed" versions of the master "st_mi_18.jpg" to use in a picture element. I guess the issue is, how do I reference these versions in my code if I didn't know the name that PW has generated? So far, PW saves them as V1, V2 etc. I want to process (in code) each version (V1, V2) so that various sizes are available to support different DPR values but obviously, I need to access each art-directed copy (V1,V2 etc). Do I just have to "know" that each version is called V1, V2 etc or, can I influence the name of the saved copy? Can I get V1 or V2 by using the $image variable with the known size/crop values and PW will return the matching Vx file? I hope this makes sense. If you have any thoughts or opinions on what I am trying to do, I'd really appreciate them! Many thanks.
  20. I use MAMP locally and the non-Pro version offers 5.6 and 7.00 only. You make a good point about the small trade-off. It's definitely worth considering!
  21. Hi @adbus - many thanks for the heads-up. I googled around and it seems that there was some kind of xdebug issue with __debugInfo() that was fixed in 2014 and there seem to be others recorded quite recently that haven't been fixed as yet. I don't want to go backwards with respect to PHP version so, I'll just have to put up with whatever issues arise on the odd occasions that they do. Again, I really appreciate you taking the time to point this out!
  22. Hi @horst - excellent answer! Many thanks indeed I am using PW3 and taking advantage of all the latest goodness! Hope you're having a great weekend and I appreciate your very quick response. Cheers!
  23. Hey @horst - the IMagick Image Sizer module uses a default "Quality" setting of 80. When using the "quality" option in PIA (or native PW $image methods), does it override the IMagick Image Sizer module or, if you specify "quality=75", is it 75 based on 80 (IMagick default), or 75 based on the original image? Hope this makes sense! Thanks.
  24. Hey @horst - you have created a beautiful lady! Thanks for giving me her number !
×
×
  • Create New...