Jump to content

Soma

Moderators
  • Posts

    6,808
  • Joined

  • Last visited

  • Days Won

    159

Everything posted by Soma

  1. Just looked like it's in a subfolder, in your error "/path/site/templates/language-gateway.php" /path/site/... So the first example doesn't work with urls which was wrong. It should be $config->paths->templates instead. <?php $page = $modules->get('LanguageLocalizedURL')->parseUrl(); include($config->paths->templates . $page->template . ".php"); Ah yes I see, this was added recently, somehow missed it or couldn't remember.
  2. BTW what is prependTemplateFile appendTemplateFile? There's no such API method in PW.
  3. Maybe because you got PW in a subfolder of webroot? It could also be written like this <?php $localizedpage = $modules->get('LanguageLocalizedURL')->parseUrl(); include("./{$localizedpage->template}.php");
  4. Nicole, that's what my first solution is like, and this is how it's meant to work. You add the two fields to the page you want them and in the template file you output markup that will take those two values as to construct the selector needed. If you set that up, nobody has to change code, but you can edit it via those 2 fields. In PW you don't get fields that output markup by itself, you need at least some echo $page->field. Of course it would be possible to make the field output a markup string and not the plain or formated value. But it goes beyond what you really need and it would take a long post to explain everything. Doing a fieldtype which has two inputfields is even more complicated and in the end it is what the template/field setup in PW is made for, so you'd only mimic what is already there. My solutions show already what you could do otherwise, you have some alternatives.
  5. Look at my corrected code, you was too fast. $page->template only returns name without ".php".
  6. The LanguageLocalizedURL module uses gateway pages that "render" (as it is a page), in there it then will "render" the content of a page evaluated by the parser. The gateway template example provided uses $page->render();. So you got 2 render. To avoid it you could change the render to include the template that would originally be used. <?php $page = $modules->get('LanguageLocalizedURL')->parseUrl(); include($config->paths->templates . $page->template . ".php"); I'm not sure again about the drawbacks of this approach, but should work.
  7. Thanks Pete, I'm happy if someone corrects me if it's vital. I just wanted to add another possiblity. You can also use the /site/config.php to add configuration you need throughout your site. Add this to the config file. $config->blogPageListLimit = 10; $config->blogPageListParentId = 1004; And you can use it wherever you need it. $pages->get($config->blogPageListParentId)->children("limit=$config->blogPageListLimit, sort=-date");
  8. Welcome Nicole. I had a look at your module and there's quite some things missing. I'm with Pete that for what you want to create there isn't the need for a new fieldtype. But I'm not sure what exactly you're trying to achieve that you have come up with this approach, what is the goal? Just to explain a little about fieldtypes/inputfields. A fieldtype always needs an inputfield associated. The inputfield is then used as the "interface" to input values. The inputfields all have a render() method that will output markup in the editpage screen at the end. Also there's a database schema you should specify and also wakeupValue, sleepValue, sanitizeValue, formatValue and getBlankValue. So you can guess it's much more sophisticated and complex than you initially thought and you're mixing a lot of thing up that makes it hard to start with. Other "normal" WireData modules that hook into something or process modules that can create custom admin pages functionality are much simpler to start with. Also the getConfigInputfields() is to have settings for your module and not for something you went here. You could use it to globally define the two values of course, but it will only be available to superusers to edit it. Solutions To get back to what you want to acheive. I think Pete is right, but I think you don't want to create a front-end form? A good solution to have this on a page to configure, simply use two fields to have a integer (or range slider) and a page field to select the parent page. Basicly what you wanted to do with your module. Then you can use them in the template code to output the list. You can attach those two field to whatever template/page you want, maybe the home page or some other pseudo "settings" page you create. A code in the template then maybe looks like this: "parent_page" being the page select, "limit" being the integer field $settings = $pages->get("/settings/"); $results = $this->$pages->find("parent=$settings->parent_page, limit=$settings->limit, sort=-date"); echo "<ul class='$class'>"; foreach($results as $result) { echo "<li><h3><a href='{$result->url}'>{$result->title}</a></h3><p>{$result->summary}</p></li>"; } echo "</ul>"; For such a small thing it isn't really needed to have a module that renders that but you could create a helper function to include in your templates, or if you really want to start with modules, I think the following might be simpler to start with. Look at HelloWorld.module aslo to learn more. This is a module you can load and use its methods to call in templates. <?php class MyBlog extends WireData implements Module{ public static function getModuleInfo() { return array( 'title' => 'Blog', 'summary' => 'Displays a Page List', 'version' => 1, 'author' => 'Nicole Bardales', 'href' => '', 'singular' => true, 'autoload' => false ); } public function init() { // attach hooks maybe, not needed here } public function blogPageList($limit = 10, $parent = null) { $class = "page-list"; /* or you could retrieve the setting from a fixed page */ //$limit = $this->pages->get("/settings/")->limit; //$parent = $this->pages->get("/settings/")->parent_page; if(!$parent) return "Specify a parent int he second argument"; $results = $this->$pages->find("parent=$parent, limit=$limit, sort=-date"); if(!count($results)) return "No pages found"; $out = "<ul class='$class'>"; foreach($results as $result) { $out .= "<li><h3><a href='{$result->url}'>{$result->title}</a></h3><p>{$result->summary}</p></li>"; } return $out . "</ul>"; } } With this you can load the module in your templates and use the method it adds to output the list. // load module, since we made it non autoload $blog = $modules->get("MyBlog"); $parent = $pages->get("/blogposts/"); echo $blog->blogPageList(10, $parent); or // load module, since we made it non autoload $blog = $modules->get("MyBlog"); $parent = $pages->get("/settings/")->parent_page; $limit = $pages->get("/settings/")->limit; echo $blog->blogPageList($limit, $parent);
  9. That's some nice ideas there. I'm sure this will come in handy and would make markup caching more powerful. I like the idea to have a module to expire them by rules. Though I don't understand those rules, are they somehow to define the cache and pages that when saved will expire something? Just to understand it correctly. 1name (cache) 1pages (pages) 2name 2pages ... Also the alternative way to create the cache is nice idea. Keep going
  10. Yeah cosmetic, but my snippets is more scalable or doesn't matter how many leves, where you would end up with ->parent->parent->parent About snippets like this people often ask if there's a simpler way or more elegant. I often wonder what it would take in other CMS' to archive this
  11. There's no "easy" way. There this new module by Ryan, http://modules.proce...eldtype-concat/ but that isn't for this case and use in find(). But you could find the pages and foreach the resulting PageArray, then cycle them and calculate the prices and store them to the page temporarely. Then sort by that property. For example: foreach($products as $p) { $p->endprice = $p->price + ($p->price / 100 * $p->vat); } foreach($products->sort("-endprice") as $p) { echo $p->endprice; } You could make a module that creates a function to $pages, so you could use $pages->findProducts();. Or have an php include with functions that you can use the above with a simple call like "echo getProductsList();" in your templates
  12. Hmm not sure, this would be easier (back to root) using parents->has() if ($allowedPage->parents->has($page)) $session->redirect("$allowedPage->url"); Another option would be to test in the clients, and client template to check if access is granted and redirect. So simply a role, permission based solution.
  13. If you put the Rules right after the "RewriteEngine on", there's nothing else that would make it not work and PW rules afterwards won't get executed at all obviously. I can't think of anything why it shouldn't work. Maybe something on your host is configured differently. Could it be that files with two "." in the filename are a problem for you?
  14. Hm and where in the htaccess have you added the rules exactly?
  15. It works fine here (tested). The request of an image from another domain is blocked. If pw is installef or not doesnt matter. The request doesnt get processed by pw in any way only the htaccess gets into play.
  16. That response doesn't make much sense me, but I don't know what their protection is. Images are physical and there's nothing more special about it, than if you'd put a static html with an image that lives in a folder somewhere. Adding this to after the "RewriteEngine on" in the PW .htaccess will protected any image request that does not come from the domain specified. Works well. RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.ch [NC] RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
  17. Fact is your code is perfectly fine for what it archives. You'll not find any modules that could help you doing it, at best the MarkupSimpleNavigation. It is well for quickly rendering straight nested navigations. You can overwrite with you own templates and selector (global) etc, as the manual shows. However it is not suited for things like you do with products and categories as it just traverses the page tree or parts of it. For more complex navigation the PW API and the hierarchical structure makes it very easy to construct them the way you did. I wouldn't start putting it to pieces with abstraction and functions for this menu. You problem with navigation not showing when no products found would be easy with moving the output after iterating the products and test if they're linked. Then echo only if any found. For example: foreach($applications as $a) { $prod_str = ''; foreach($products as $p) { if(!$p->applications->has($a)) continue; if(!$p->sectors->has($s)) continue; $span = $p->new == 1 ? " <span class='orange sub-menu-title'>" . $this->_('novita') . "</span>" : ""; $prod_str .= "<li><a href='$p->url'>$p->title$span</a></li>"; } if($prod_str){ echo "<li><a href='$a->url'>$a->title</a><ul class='sub-menu'>$prod_str</ul></li>"; } }
  18. From 7 to 3 pm spacific time for that price?! So are the chicks and beer included? For that price i expect them to clean my shoes too
  19. Omg the internet is full of links!!
  20. Theres nothing special about how pw handles file requests so you should be able to add the rules to the htaccess of pw.
  21. Sorry to not get back any sooner. What do you mean to clean up the code and make it dry? It actually looks good and clean. I don't think you can easily reduce or simplify with the special case of menu you got. I havent looked closely at your code before when i posted that. I dont see an easy way to use my module to create this sort of navigation. only partial at best. Sorry to confuse you. I think nobody really poped in to help you because it is already good and people dont like to clean up or code it for you. I guess you know why. Ive done it occasionally and only because ive thought the requester has no clue. So you come with a big list of how it should work and it looks as you want it to someone else make it for you. That most likely wont work here. If you post a specific question of something you cant get to work Im sure somebody will try to help. Again your code looks fine to me and you get the most out of it with simple foreachs. I don't think theres much to dry here.
  22. It has problems if you change a image field to cropimage field. At least it was for me.
  23. Soma

    Happy new year!

    3 minutes to go!! Hapoy new year everybuddy!
  24. It's somehow assumed, as the php equivalents you can also use -n, array_slice or substr etc.
×
×
  • Create New...