-
Posts
358 -
Joined
-
Last visited
-
Days Won
9
Everything posted by monollonom
-
change current pages template file at runtime?
monollonom replied to applab's topic in General Support
Seems like you could also hook into WireFileTools::include, which is used behind $files->include or $files->render, maybe you could do the same check / filename replacement there. (as per my edit in the previous message I managed to not only miss an important point but also the fact you already had a similar code... ?) -
change current pages template file at runtime?
monollonom replied to applab's topic in General Support
Ah, somehow I missed the part where you said you needed to fallback should the file not be there, my bad! Edit: I even missed the fact you already had a similar code ? From what I'm reading in PW’s source code, you could hook before TemplateFile::render (...time passing doing tests...) I think the best is to check if the dev’s file exists and then use setFilename() in init.php: wire()->addHookBefore("TemplateFile::render", function(HookEvent $event) { /** @var TemplateFile $tpl */ $tpl = $event->object; $userTpl = str_replace("templates/", "templates-dev/" . $event->user->name, $tpl->filename); if(file_exists($userTpl)) { $tpl->setFilename($userTpl); } }); Try and let me know if it works for you! -
change current pages template file at runtime?
monollonom replied to applab's topic in General Support
I actually share a similar setup but for another use (templates-dev is for local development / preview) and in my case I use this in my config.php: $config->urls->templates = $config->urls->site . "templates-dev/"; $config->paths->templates = $config->paths->site . "templates-dev/"; $config->urls->fieldTemplates = $config->urls->site . "templates-dev/fields/"; $config->paths->fieldTemplates = $config->paths->site . "templates-dev/fields/"; Similar to what @androbey suggested. However I don’t switch based on the user but it's easy to do so in your site/init.php if($user->name === "username") { // ... } elseif($user->name === "admin") { // ... } -
In this case, best is to simply go with either an "if" or "switch" statement, something like: $datum = $concert->date; $format = "E, d. LLLL yyyy, HH:mm"; switch($user->language->name) { case "deutsch": $lang = "de-DE"; $format = "EE dd.MM.YYYY"; break; case "français": $lang = "fr_FR"; break; case "default": $lang = "en_US"; break; } $fmt = new \IntlDateFormatter($lang, \IntlDateFormatter::FULL); $fmt->setPattern($format); echo $fmt->format($datum);
-
You mean the multi-lang site profile? I assume your default language is English then, did you try the code I gave you? The important part is replacing new \IntlDateFormatter('DE', with: new \IntlDateFormatter($user->language->isDefault() ? "en_US" : "de-DE" And if it happens to be the wrong way around, just invert "en" and "de".
-
@Thomas -Allwinds Webstudio when creating your IntlDateFormatter, do you set the locale based on the user’s language or is hard-coded like in your code sample? It depends on how you named your languages or which one is your default but maybe it could be: $datum = $concert->date; $fmt = new \IntlDateFormatter($user->language->isDefault() ? "en_US" : "de-DE", \IntlDateFormatter::FULL ); $fmt->setPattern('E, d. LLLL yyyy, HH:mm'); echo $fmt->format($datum);
-
I just came across this issue and the solution is pretty simple: replace strftime() with date("YmdHMS", $seconds) I don't really understand the use of strftime() here since there's no use of language-dependent strings... @horst Could you have a look at this or would you rather accept a PR?
-
Hi @adrian, would you consider adding your fork in the module directory so we can update it using ProcessWireUpgrade? That would be great!
-
I have the same case where I use a start date and an end one. I add a hook that checks the end date when saving the page and if undefined it copies the start date value, this way you can sort using the end date.
-
If you're on Mac, you can try/buy https://www.araelium.com/screenflick-mac-screen-recorder. I'm just using it for basic screen recording but it seems it could do what you need (except for "append videos" maybe), plus it can be simple enough.
-
New video: How to add RockMigrations to an existing Project
monollonom replied to bernhard's topic in RockMigrations
@wbmnfktr I'm not using @bernhard’s tool but you could go this way to have your initial migrate.php: $rm = $modules->get("RockMigrations"); $excludedFields = ["admin_theme", "pass", "permissions", "process", "roles"]; $fieldsCode = []; foreach($fields as $field) { if(in_array($field->name, $excludedFields)) continue; $fieldsCode[] = $rm->getCode($field); } $fieldsCode = "\$rm->migrate(\"fields\" => [\n" . implode(",\n", $fieldsCode) . "\n];"; $excludedTemplates = ["admin", "permission", "role", "user"]; $templatesCode = []; foreach($templates as $template) { if(in_array($template->name, $excludedTemplates)) continue; $templatesCode[] = $rm->getCode($template); } $templatesCode = "\$rm->migrate(\"templates\" => [\n" . implode(",\n", $templatesCode) . "\n];"; And export $fieldsCode and $templatesCode in a file. Regarding the verbosity, it unfortunately boils down to how PW generates the export data. You could be pretty agressive and skip all falsy values but you might get unexpected behaviour. -
TagsToFolders Github: https://github.com/eprcstudio/TagsToFolders Modules directory: https://processwire.com/modules/tags-to-folders/ This is a small helper tool to visually organise fields/templates into folders in the menu when they are tagged. This is a simple module that can help you declutter your templates/fields menu by organising them in folders using tags. I initially envisionned this module to be used for cases where fields and/or templates were created by modules and thus not polute the ones created by the user.
- 7 replies
-
- 18
-
-
-
I've made yet another update, re: minification part + I came back to adding the debug view right after <body> like I did before, otherwise it did weird stuff to the layout. But this time I made sure my replace also handle cases where the <body> tag has an attribute, to counter the issue you had @wbmnfktr.
-
Okay so I published the update fixing the issues. And for your case @wbmnfktr I added an option where you can disable the minification if it's messing your layout. By default MJML adds a lot of clutter (whitespaces) in the code and my module is pretty agressive (dumb?) in the way it handles this. So in such case, this option will help out, though you'll get a heavier code (better this way than a non-working one heh). Please let me know if you notice any other issue.
-
Me making bad assumptions ? How about changing these lines to replace "</body>" to "$view/$rawButton</body>" ? It will be safer now that I'm seeing this. (my bad for not seeing the second half of your issues)
-
Happy new year to you too @wbmnfktr ! I'm sorry you're facing this issue, most likely it's because I'm removing a space before your <strong> tag here PageMjmlToHtml.module line 161. I'm not at home until next week and can't push a fix but you can either just comment this line and the next one or you can edit the lines so the regexes look for a space / \n only after "<" and before ">": Hope this helps !
-
I noticed an issue with the regexes used for minifying the (working) output. I don't know why it didn't come up before but I just had the bug and fixed it. Still "beta" ?
-
Could you share a bit more about your setup ? Is your file input set to receive several files ? I don't really see why you're using glob when you could maybe just use: if(!$page->webfont_archive->count() && !$page->text) return; // we're assuming webfont_archive is set to return a PageFiles and not a single PageFile foreach($page->webfont_archive->find("ext=svg") as $svgFont) { $svg = new EasySVG(); $svg->setFontSVG($svgFont->url); // try ->httpUrl or ->filename if not working /* ... */ } But again it might depend on your setup ?
-
Help - Suggestions on reusing a background image across a site.
monollonom replied to Greg Lumley's topic in General Support
There is also this module by @Robin S Lots of options to choose from ? (though @bernhard’s might be more suitable as it allows to select only one image) -
I pushed a new version with two additions: the first one adds the ability to select specific roles to bypass the cache and thus convert the MJML code on each page render. I don’t think it will be used much but it’s there in case the cache invalidation when saving the page or updating the template’s file is not enough the second one is more interesting as it adds the ability to generate a unique output per GET variable. Previously a GET variable would just output and save to the page’s cache but now you can specify GET variables (or the wildcard "*") to have a cached version per variable. Please note though that, when rendering, if there are several GET variables only the first one is used. `raw` is ignored as it’s used by the module. My current use-case for this is having a "browser" version (with ?browser) where I can display a newsletter with the right webfont. I also added a small note in the settings regarding TracyDebugger to invite module users to disable the panel bar for the MJML templates. TracyDebugger hooks to `render` as well and thus some of its markup might end up in the converted code when showing the `raw` version. I think by now this can be considered "beta", though please test on your local environment first and let me know if you notice anything.
-
I don't know if anyone pm'd you already but it can be quite simple if you only need to generate a static svg from a text input. I found this library https://github.com/kartsims/easysvg which would allow you to do it all server-wise if you have .svg font files at hand. My approach would be to have a file input for the font file, a text input for the text you want to generate the svg from, a textarea (closed by default and non-editable) to hold the svg code, and something like https://processwire.com/modules/inputfield-runtime-only/ to echo the textarea's content (the svg) as a preview. Basically a hook in `ready.php`: require "/path/to/easySVG.php"; wire()->addHookBefore("Pages::saveReady", function(HookEvent $event) { /** @var Page $page */ $page = $event->arguments(0); if($page->template->name !== "font") return; // or whatever if(!$page->fontfile && !$page->text) return; // file and text inputs // copy/pasting from easySVG example $svg = new EasySVG(); $svg->setFontSVG($page->fontfile->url); $svg->setFontSize(100); $svg->setFontColor('#000000'); $svg->setLineHeight(1.2); $svg->setLetterSpacing(.1); $svg->setUseKerning(true); $svg->addText($page->text); list($textWidth, $textHeight) = $svg->textDimensions($page->text); $svg->addAttribute("width", $textWidth."px"); $svg->addAttribute("height", $textHeight."px"); $page->svgcode = $svg->asXML(); // textarea input $event->arguments(0, $page); }); And in your `svgpreview` field/file (check RuntimeOnly doc) or template file: echo $page->getUnformatted("svgcode"); (I used getUnformatted in case there are textformatters but it would best if there's none in the field's settings) It's not tested and made on top of my head but I think this might work. (nice to see Velvetyne here btw, I like your work and a good friend of mine made La Savate ?)
-
Thanks for the fix. I was almost there it seemed but missed a bit of php knowledge ?
- 18 replies
-
- inputfield
- images
-
(and 2 more)
Tagged with:
-
Hi @Robin S, I had an issue and just found a solution, but I can't explain why it's behaving this way: Given the setup mentionned in my previous post, when saving after selecting images it worked fine. But then if I saved the page without changes it cleared my selection. Trying to debug I checked if it was an issue with my image, my loops, had a look at your code but in the end what mattered was the artwork's id used as the option's value. Apparently if the option's key resolved to an int it got cleared ("1" was working though and "0" as well but then no image was shown in the selected part, weird). My solution was to add a prefix (e.g. "id1024") and then it worked as expected. I have to point out this is only happening with the SelectImages inputfield type, if I use AsmSelect, then it works as expected. Do you have an idea why it's behaving this way ? Thanks !
- 18 replies
-
- 1
-
-
- inputfield
- images
-
(and 2 more)
Tagged with: