-
Posts
174 -
Joined
-
Last visited
-
Days Won
2
Everything posted by blynx
-
Hej, hummmm - I'd add the advice not to let yourself drown in those buzzwords and stuff. Every time I learn something completely new, I run against this wall of all those phrases and things and buzzwords maybe and blah and so many stuff I don't know and try to grasp it all at once but—of course that's not possible. Instead, everything will come together after a while—almost automatically—if you just start to work with processwire (or whatever). As you said, grab the next best "starting at zero" tutorial and—again, ignore the confusion about all the unknown things!—just dig yourself through it. Sometimes you will be stuck - but then sometimes it will also make "click!" ... and the clicks will come more and more often ... And also ask questions here! Without knowing, you will have learnt the difference between a "template" and a "template file" ... I think https://processwire.com/docs/tutorials/hello-worlds/ pwired suggested is very good, because you will start from a simple HTML page which could also live without processwire - but you will integrate processwire into that page step by step. (Or maybe it's rather the other way around - as you see it ...) Whats your general programming / website building experience btw?
-
Hej, I think thats no problem. When you have the link between synonyms and entries like I described, it is easy to retrieve the tags from the entry when you query a synonym: <?php # # "linked_entry" is the page field on the synonym holding the # reference to the entry. # synonyms have no tags field. # // get the tags of synonyms $a_synonym = $pages->get("parent=synonyms, name=airplane"); $synonyms_tags_via_its_linked_entry = $a_synonym->linked_entry->tags; // edit: in one line: $synonyms_tags_via_its_linked_entry = $pages->get("parent=synonyms, name=airplane")->linked_entry->tags; // find synonyms with tags $those_synonyms = $pages->find("parent=synonym, linked_entry.tags=some_tag|another_tag"); You just need to tag your entries and through the link in the synonym its very easy to handle anything tag related. But the syncing you describe would still be possible - though I don't think you need that if the tags of the synonym and the entry will always be the same. Regarding hooks: Have a close look at https://processwire.com/api/hooks/ and this when you got the idea: https://processwire.com/api/hooks/captain-hook/ and also search the forum for more examples! This is a rough sketch of a hook that might sit in the init.php / ready.php file. It may work out of the box, but I am still in the trial and error phase when it comes to hooks and haven't teste this one but it should work more or less somehow like this: <?php # keep synonyms linked_entry in snyc with entries synonyms wire()->addHookAfter('Pages::saved', function($event) { $page = $event->arguments(0); // what page was the hook called on? $template = $page->template; // what template has that page // see if the saved page is an entry because this hook is called on every page save if($template == "entry") { /* $related_synonym_pages = $pages->find("parent=synonyms, name={$page->synonyms}"); foreach($related_synonym_pages as $syn) { $syn->setAndSave("linked_entry", $page); } */ // haha, this happens to me all the time, the following should be simplier =) foreach($page->synonyms as $syn) { // get the set synonyms directly from the page $syn->setAndSave("linked_entry", $page); // set this page to that synonym } } }); So, this is the hook for: Edit synonyms on entry page, save it → hook updates the related synonyms which are set on the entry page enjoy
-
Hm, well - regarding "thousands of pages": There was this blogpost once: https://processwire.com/blog/posts/find-and-iterate-many-pages-at-once/ about the new findmany() function: https://processwire.com/api/ref/pages/find-many/ - but from my understanding, this only applies if you really want to retrieve and do something with that many pages. In an encyclopaedia application you will of course search inside of manymany pages but you mostly only retrieve one or a small subset. I would assume (though I am not an expert) that the findMany() case does not apply here. The actual link will actually be the other way around. The synonyms don't know anything about their relation to someone else. That's why I was referring to the tagging: You have the entries and they point to synonyms: plane → aircraft, ufo, flying saucer, … but with your application logic you can create that link. Assuming: entries plane car fork ... synonyms airplane automobile ufo flying saucer ... Then, for example you get a query for "airplane": <?php $incoming_query_term = "airplane"; $entry = $pages->get("name=$incoming_query_term, parent=entries"); // see if there is an entry if($entry instanceof NullPage) { // no entry? $synonym = $pages->get("name=$incoming_query_term, parent=synonyms"); // get the synonym $entry = $pages->get("synonyms=$synonym, parent=entries"); // get the entry which has that synonym in its synonyms page field // eh, should also work, combined and short: $entry = $pages->get("synonyms=[name=$incoming_query_term, parent=synonyms], parent=entries"); } I guess your tagging should work kind of the same? edit: Mh, reread your original post - I think it would be more complicated to have the synonyms in a field. Maybe it feels stupid to have extra pages for the synonyms but I think it is the better solution. The downside is maybe that database queries take longer - but since processwire has the findMany() method now I don't think it is any problem to handle that many pages. One consideration might be helpful for rendering the list: Without this you would have to retrieve the entry for a synonym for every synonym by code like $pages->get("synonyms=THIS_SYNONYM.id") ... You could link from the synonyms to the entries by giving them a page field, too, where you store the linked entry. You could create that link with a hook automatically every time a synonym is created, so that every synonym has an entry-link. The problem here is to keep the links coherent. But then it would be very easy to render the list: Find all entries and all synonyms to one PageArray (probably paginated then, findMany?). Sort by name. Render them accordingly to their type: Entries become direkt links to the entry, synonyms become that "aircraft → plane" output.
-
Mh, The synonyms field could be a simple textarea field "synonyms" on the "root word" with a synonym in each line. And when you are looking for the root page for a synonym: <?php $pages->find("synonyms*=requested_synonym") // or ->get() Would this do it? But I'd say having synonym pages might give you more flexibility - maybe you want to add properties to synonyms later .. who knows ^^. I don't think it is a downside having lots of "empty" pages. I probably would store all synonyms in a synonyms folder page as a storage and having a page field on the actual entry with that inputfield: http://modules.processwire.com/modules/inputfield-page-autocomplete/ It'll basically just be like tagging and one doesn't have to think much about those tag / synonym pages. They can be hidden somewhere. Finding correlating pages would work like above. (Not sure about the *= though, works with just = on a setup I have). This might also prevent you from some errors since every synonym is an actual entity in the system.
-
Your $thumbnail is already pretty handy - you could write somthing like $image->size(123, 456)->url but then you would have to repeat the size command all the time. Then, in your last example you have to put the "single-product-wrapper" into the foreach loop, since you want to wrap every product with it .... ‽ ... And what BitPoet said.
-
@kuba2 You are welcome : ) Actually I learned a lot PHP and Object Oriented Programming just through Processwire - you should really look into the processwire documentation http://processwire.com/docs/ - especially about template files and selectors in the beginning - later you will really enjoy http://processwire.com/api/ref/ the API reference where the most important things are documented. @SamC well, but your reply is way more sophisticated!
-
Hej! Could you post your current code so we can see what's wrong? A couple of links that might be useful: https://www.smashingmagazine.com/2016/07/the-aesthetic-of-non-opinionated-content-management-a-beginners-guide-to-processwire/#getting-the-current-page-with-the-page-variable http://processwire.com/api/templates/ http://processwire.com/api/templates/ Generally it should / could be something like this: This could be the template file for a product - but with the actual names of your fields and so on ... <html> <head></head> <body> <?php foreach($page->children() as $product): ?> <div> <img src="<?= $product->img->url; ?>"> <h3><?= $product->title; ?></h3> <p><?= $product->inhalt1; ?></p> </div> <?php endforeach; ?> </body> </html> I used shorthand <?= ?> tags and the <?php foreach(): ?> <?php endforeach; ?> alternative control structure thing here which I really like (http://php.net/manual/en/control-structures.alternative-syntax.php) But it is up to you how to implement it. Hope that helps lg Steffen
-
Hej, you will get the current hostname via $config->httpHost if($config->httpHost === "dev.malabu.de") { echo "<link rel='stylesheet' href='dev.css'>"; } else { echo "<link rel='stylesheet' href='style.css'>"; } another approach could be to check if the visitor is superuser or has a dev role (add a "dev" role before) and assign it to your dev account – and then, similar to above: (you don't have to setup subdomains then ...) <?php if($user->hasRole("superuser")) { ... } else { ... } ?> <link rel='stylesheet' href='url/to/css/<?= ($user->hasRole("superuser")) ? "dev.css" : "normal.css" ) ?>'> or like in the last line with the shorthand if/else syntax
-
Wireinput only allows one-dimensional arrays - why?!
blynx replied to Rob's topic in API & Templates
Just stumbled upon it, too. Actually, what are these security concerns? -
Ah ok! Then I also understand your code : ) Actually I think this should be it - I just discovered a typo! It should be "import" not "improt"
-
hej, hmmm - could you give some more details about the situation? What is the data, what do you want to do with the data? Do you want to render a form with radio buttons from a PageArray? What I suggested was just a method to reorder whatever PageArray according to a new order - Maybe the $pages->find() shouldn't be in the loop anyway - rather before the loop to get the data once? But right now I think I need more information about the situation actually to make useful suggestions. cheers, Steffen
-
You could set up an array which maps your custom ordering and then loop over it and get/put your data accordingly ... !? $my_custom_order_map = array( 1 => 3, 2 => 2, 3 => 1, 4 => 4, … ); $new_order = new PageArray(); foreach($my_custom_order_map as $pos) { $new_order->append($old_page_array->eq($pos)); } best wishes, Steffen
-
Thanks horst for the list and for pointing things out! But I think this doesn't fit my needs? I want to display that template in an iframe which should not have any processwire markup added. The modal mode removes the processwire interface but still includes pw css, js, header, this and that… But I also found another reason for copying the template file into site/templates - it might be useful to edit that file and modify the rendering of those pages.
-
Hi apeisa, actually I am using a template file now - because I "found out" that the stuff I want to render gets the data from a page under that process and they exist anyway. ... Too obvious ... Still, I'd like a solution where I wouldn't have to move some template file from that module into the site/templates folder. Feels kinda like "pollution" for me. Wonder if it is possible to trick processwire into thinking a page without template file actually has one and tell it to take a file from the module folder?
-
Hej! Aha! Thanks @horst for the hints, I found out that simply providing the "modal=1" GET variable will render any process page without the processwire interface. Leaving it out you will see the process inside processwire. Clever thing ... Cheers, Steffen EDIT: ok ... the modal version still has processwire <head> and stuff - so that's not what I want. I found another solution for my problem (maybe even better), but if anyone has any idea how to completely replace the markup from the admin page, let me know!
-
Hi @horst! Hmmm - when I access an admin page with a process like "http://domain.de/processwire/customadmin" the output of execute() will be put into the admin interface - How are you accessing/displaying those pages? Where can I find the place where the modal windows gets created/called? Couldn't find it right now ...
-
shzzzzz .... yes it is just there "bd()" - don't know what went wrong here ^^ I was working in the execute() function of a Process module Thanks!
-
Hej, is there another way (one-liner) to use TracyDebugger in modules instead of "use\Debugger" & "Debugger::barDump(...)"? (working on a process module, namespace Processwire) cheers, Steffen
-
Hej, I am working on a Process Module which should display an html template in an iframe which I want to put through wirePopulateStringTags(). So I thought I'd set the src of the iframe to an executeIframe() function of that Process - but that would of course return the whole admin page. Is there a way to surpress the rendering of the admin interface and just send back the html file? I don't want to set up a page with a seperate template in the page-tree just for that feature. Otherwise I guess I'd make a helper php script ... Or does anyone have another idea? Cheers, Steffen
-
Yes! Thanks @LostKobrakai, thats it - should've tried that one too ... @Martijn Geerts, yep - I also tried wire('config') but that didn't work either – and I was not sure about `template=` vs. `template.id=`, too ... both work though PS: Is there actually some kind of summarized documentation of where which variables are scoped and why? Like to get to know some underlying concepts of processwire? Or a forums thread where things like that are explained more thoroughly?
-
Hej, i am trying to build a custom PHP code selector to get all pages using a user template for a site using multiple templates for users. Here are my two non-working approaches: /** * A */ return function() { $template_ids = implode("|", $config->userTemplateIDs); return $pages->find("template=$template_ids, include=all"); }; /** * B */ return $pages->find("template=".implode("|", $config->userTemplateIDs).", include=all"); Maybe I am thinking too complicated and I miss something here - basically I need a Page Field which can select from all users with all the different user templates ... uhm - has anyone an idea how this might work? Also in general - has anyone an idea what is actually possible with this custom php code selector? I guess it is somewhat restrained? Thanks! Steffen EDIT: I guess that I can't access $config?
-
Meanwhile we fixed it, there was some "}" missing somewhere, thanks for the addition @horst!
-
Hej, just sent you a DM, maybe send me your site and I can have a look - maybe the error is somewhere else hidden!?!?
-
Ok tested the approach here, works fine ... Ah, I meant the projects - has every project page an actual image inside head_image? (Well, might be a silly question but who know ^^)