Oliver
Members-
Posts
167 -
Joined
-
Last visited
-
Days Won
6
Everything posted by Oliver
-
@Nurguly Ashyrov, this is really awesome. My front-end work is mostly JS/SPA work these days and I learnt to love the “headless”/“api first“ approach of commercial CMSes like Contentful. So I often thought about what a perfect and easy to manage back-end ProcessWire would be with a solid HTTP-based api built right in to allow uncoupling actual front-end/ui parts like admin and user interfaces (as actual self-contained apps) from the CMS itself. A module like yours makes a huge leap in this direction and will make ProcessWire much more interesting for a lot of front-end devs and e.g. as a flexible and fast to set up back-end for app prototyping/mvp development. A pity this didn’t exist 9 month ago!
-
I moved to Berlin in April and left behind the graphic design studio I co-founded in Basel to get myself more into digital product design. Last week one of my old clients from Basel approached me because they are currently thinking about implementing an own web shop on their website (run on PW). Now I’m looking out for a Berlin-based PW dev with experience in implementing web shops (external platforms or/and PadLoper) in a PW environment who would be interested in collaborating with me on this. I’d mainly work on the design and provide support with the project/code structure on implementation. If this sounds interesting to you, get in touch! If you are very interested and not based in Berlin, don’t hesitate to reply anyway. Thanks in advance!
-
I just wanted to vote for making Template class’ filenameExists method hookable. Would become handy as soon as you don’t want to work with native template files the usual way without all pages being marked as not viewable. BTW: As the hook method viewable provided by PagePermissions is the main problem here, it would be good to know if it were possible to override existing hooks of other modules somehow. Just a thought.
-
Ok, looks as I just didn’t see the tiny text below the input field. Having the icons at hand in the new version is pretty awesome. Thanks for the hint!
-
Oh. Where exactly do I have to set a template’s icon? Can’t see anything icon related in template settings (PW 2.5.3).
-
Hey felix, did I miss something or what icons are you taking about here? Is there actually a way to assign icons to templates? Regarding usability and as pages could be a thousand things like actual viewable pages, folders or partials, it would be really, really great to be able to display a font awesome icon in front of the page names in the page tree. Could be a document icon as default, but e.g. a globe for a subpage that is accessible through an own domain or subdomain. It would make even more sense to me than having icons displayed next to input fields, as they come with a specific label, description and appearance.
-
Awesome, horst. I want this in PW core! Dealing with the issue of resizing animated gifs was each time a pain in the ass. Actually I have a project coming up with an image grid that contains several animated gifs. So I will definitely give it a try.
-
Great! Let me know if you got other issues or feedback.
-
I absolutely get your point, Soma. I’ve always been a trial-and-error kind of coder, so I tried a lot, built a lot of stuff the way I thought was right. I hated how bad my code was structured and how hard it was to maintain. So I experimented with ways to separate things, tried approaches like your “delegate” one but didn’t really arrive at a point of happiness. As I said I have been experimenting with other languages and frameworks like Ember, Rails etc. and I really fell in love with the burden of defining a meaningful and comprehensible structure being taken off me. Of course, the thing that brought me to PW was its freedom. But for me as a designer it was especially the freedom of how to build templates (as data containers) and how to present them easiy with PWs API at hand in your template files. But as soon as you want your PW site to do more than render web pages it (at least in my semi-semi-pro-dev experience) gets messy pretty fast when you try to wire things up to make a page do more than one thing. So I really think it’s justifiable to use PWs modular base to build a MVCish layer upon it. Especially when you think of the fact that native page rendering has been a module itself from the start. Of course it’s not ideal to have a dozen of concepts around. I’ve kept an eye on earlier modules/concepts going in a similar direction but they mostly just dealt with a certain part of my issue. So I started experimenting (again) to create kind of a proof of concept and I wanted to share this with the community. If there is a real MVCish approach that is/will be supported by PW Core Team I’d be more than happy to support it. Did I miss something here?
-
@fmgujju: I guess I solved it. It was a minor error when passing method calls through my PvcPageProxy class. Grab the latest version from github and give it another try. Thanks for testing. There has been another error in my examples above: In products’ action template for index you have to add ->url at the end of the PW API call within the src attribute of the img tag to make it show the images.
-
I’ll try to reproduce it. Thanks for the corrections.
-
Right after installation? Or have you already set up some controllers or views?
-
Well, I’ll give you a short example to demonstrate how it all works together. Imagine the following simple setup: Page Tree Home |- Products (template=products) | |- Product 1 (template=product) | |- Product 2 | |- Product 3 | |- Product 4 | |- Product 5 | |- ... Page Products with template “products” is meant to show a gallery of product images. So we create a controller for the template (that otherwise would be auto-generated on the fly) in site/templates/controllers/ named products.controller.php. <?php /* site/templates/controllers/products.controller.php */ class ProductsController extends BaseController { // init() is executed on controller setup before action is called public function init() { // Just in case you defined general stuff in BaseController’s init() method parent::init(); // Set (for all actions of this controller) a script 'jquery/my.jquery.plugin.js' in group 'footer' with priority 5 // In layout and template you can then output the scripts group 'footer' using view helper <?=scripts('footer');?> // Assets defined via path are looked up in the corresponding folder within site/templates/assets/. You can alternatively // define assets using a URL. $this->script('jquery/my.jquery.plugin.js', 'footer', 5); } // index is the default action executed if no other route matches public function index() { // Add (for this action only) a stylesheet 'gallery.css' to group 'footer' with priority 10. // In layout and template you can then output the styles group using view helper <?=styles('footer');?> $this->style('gallery.css', 'footer', 10); // Set a template var 'products' that contains current page’s children as PageArray $this->set('products', $this->page->children('template=product, sort=title')); } } We’ll need an action template for products’ index action in site/templates/views/products/ named index.tmpl.php. <!-- site/templates/views/products/index.tmpl.php --> <h2><?=$title?></h2> <ul class="products"> <?php foreach($products as $product) { ?> <li class="products__item <?=gridClass($product->images->first(), 'products__image');?>"><a href="<?=$product->url?>"><img src="<?=$product->images->first()->url;?>" alt="<?=$product->title;?>"></a></li> <?php } ?> </ul> We’ll have a look at the used view helper gridClass() later. The first page in PW’s page stack (the one rendered through processPageView directly) is rendered and outputted in a layout’s outlet. Layouts are stored in site/templates/layouts. There is a default layout default.tmpl.php preinstalled. The rendered action templates are outputted within the document structure by using <?=$outlet?>. You can add as many layouts as you want and change the layout the action template will be rendered in by setting another template within your controller’s init() method like this: ... public function init() { parent::init(); // use layout site/templates/layouts/shop.tmpl.php for this template $this->set('layout', 'shop'); } ... Our product template of course also gets a controller: <?php /* site/templates/controllers/product.controller.php */ class ProductController extends BaseController { public function init() { parent::init(); // assign route pattern with dynamic segment to action 'reviewVote' $this->route('/reviews/:id/vote/', array('id' => '^[0-9]+$'), 'reviewsVote'); } public function index() { // set dynamic value to be calculated right before rendering the action template $this->set('similarProducts', function() { // your logic to get a PageArray of similar products goes here $tags = $this->page->get('tags'); // or $tags = $this->get('tags'); as it will pass the request through to page, if 'tags' isn’t set on controller itself $similarProducts = ...; return $similarProducts; }); } // action accessible via route /reviews/ public function reviews() { // we should set up this for pagination in template settings $this->set('reviews', $this->pages->find("template=reviews, product={$this->page->id}")); } // action accessible via route /reviews/new/ public function reviewsNew() { // Later versions will allow to handle actions depending on REQUEST_TYPE, but for now: if($_SERVER['REQUEST_METHOD'] == 'POST') { // create review logic goes here ... $this->session->redirect(...); } else { $this->set('form', $this->forms->get('review')); } } // action for action route /reviews/:id/vote/ public function reviewsVote() { if($id = $this->input->route->id) { // save vote for review ... } } } Template product’s action templates go into site/templates/views/product/ named index.tmpl.php, reviews.tmpl.php, etc. When we talk about routes in PVC, it means patterns of PW’s urlSegments. If you want to have multiple actions and routes, you have to enable urlSegments for the particular template. Index action is performed when a page is addressed directly via its path. If urlSegments are added to the request, PVC captures the urlSegments as a action route and provides it to the controller which determines the action to perform for the route. Until now all template specific view classes (like ProductsView, ProductView) are generated on the fly. Let’s use some view helpers to reduce logic in templates. For example we want pagination looking all the same all over the site. Therefor we define a general view helper for that in site/templates/views/base.view.php. <?php class BaseView extends PvcView { /** * Add custom view helpers that will be available as * global functions within your templates. * @method customViewHelpers * @param Array $scope contains an associative array of template scope * @returns Array An associative array with key/closure pairs */ public function customViewHelpers($scope) { return array( /** * Each helper is defined as a pair of key (name of the helper * function in template context) and closure (function body) * Via use() you can pass in $scope and custom values to be * available within your helper. * The helper below can be called like this: <?=sayHi('your name');?> */ 'pagination' => function(PageArray $pageArray) use($scope) { return $pageArray->renderPager(array( 'nextItemLabel' => "Next", 'previousItemLabel' => "Prev", 'separatorItemClass' => "pagination__item--separator", 'nextItemClass' => "pagination__item--next", 'previousItemClass' => "pagination__item--prev", 'currentItemClass' => "pagination__item--current", 'lastItemClass' => "pagination__item--last", 'listMarkup' => "<ul class='pagination pagination--{$scope['template']}'>{out}</ul>", 'itemMarkup' => "<li class='pagination__item {class}'>{out}</li>", 'linkMarkup' => "<a href='{url}'><span>{out}</span></a>" )); }) ); } } Now you can render your pagination in your action templates just by passing a PageArray value to your pagination view helper like <?=pagination($reviews);?>. You also can create template-specific view helpers (like gridClass() used in our products action template for index at the top) by creating a view class for the template in site/templates/views/ like this: <?php /* site/templates/views/products.view.php */ class ProductsView extends BaseView { public function customViewHelpers($scope) { $helpers = array( 'gridClass' => function(PageImage $img, $class=null) { $w = $img->width(); $h = $img->height(); $orientation = 'square'; if($w < $h) $orientation = 'portrait'; if($w > $h) $orientation = 'landscape'; return is_string($class) ? sprintf('%s--%s', $class, $orientation) : $orientation; } ); return array_merge($helpers, parent::customViewHelpers($scope)); } } Predefined view helpers are for example embed() to render other pages within your current action template, scripts() and styles() to output asset groups and snippet() to render reusable code chunks stored in site/templates/snippets/ within the current action template’s scope. Hopefully this gives you a vague idea how you can organize your code base using PVC.
- 13 replies
-
- 10
-
Introducing PVC PvcCore: https://github.com/oliverwehn/PvcCore/ PvcRendererTwig: https://github.com/oliverwehn/PvcRendererTwig/ (coming soon) PvcGenerator: https://github.com/oliverwehn/PvcGenerator/ (coming soon) Each time I’ve built a ProcessWire page I’ve struggled with organizing (and separating) code, markup and stuff. Playing around with frameworks (backend as well as frontend) like Rails, Ember and stuff I really liked having a given structure, knowing where to put what piece of code. Therefor I started working on a MVCish way to deal with templates in PW that considers the $page object kind of the data/model layer and adds View and Controller upon it. First by just catching everything via a small processor file added to all PW templates as altFilename. I’ve digged a bit deeper since then and hooked into the native rendering process, have been refactoring my code base more than a dozen times. Now I got a first version that seem to work and I’d love some of you guys to try it out! PVC (instead of MVC) stands for Page-View-Controller, as it considers PW’s $page var the model/data layer. I’m still working on the README.md on GitHub to document the basics. So have a look for more detailed infos there. I’ll give you a short overview here: Code separation: PVC introduces views and controllers to your PW templates as well as multiple action templates. Controllers, as most of you already know, keep all the business logic. Controllers execute actions wired to routes (urlSegment patterns). Even routes with dynamic segements (e.g. /edit/:id/) can be defined and assigned to an action, providing input through $this->input->route. Values can be set on the controller to be accessable in your templates later on. It’s also possible to set dynamic values as closures to be calculated (e.g. using field values of the current page) on render. Also controllers allow you to set layouts, styles and scripts to be available in your layout or template. Logic can be shared through inheritance between controllers. Views introduce view helpers. Helpers are functions that are made available to you (only) within your template context. There are predefined ones like embed(), snippet(), styles() or scripts(). But you can implement your own helpers easily and share them among your view classes through inheritance. Action templates contain the actual markup. Every action defined in a controller uses its own template. So the same page can display content accordingly to the action that was addressed via urlSegments/route. Within templates you can access all field values and values set on your controller like globals (e.g. <?=$title?>). Modular renderers: PVC implements rendering through separate renderer modules. PvcCore comes with PvcRendererNative that gives you template syntax the good ol’ PW/PHP way. A Twig renderer is in the making. And maybe you want to build your own renderer for the template syntax of your choice? I consider the module an early Beta version. So make sure to try it within a save environment! Would love to get some feedback (and error reports). I’m no professional developer, so code quality may suck here and there. So I’m glad for inputs on that, too. Also there is some old stuff in there yet, I still have to get rid of.
- 13 replies
-
- 16
-
I think we would have to put together kind of an active “Shop Development Group”. I love coding, but I’m definitely not that much a developer to lift a task like this. But I have some ideas on how to structure the modules to achieve a maximum of flexibility regarding how to layout your shop within the page tree. Splitting the challenges is small packages may be the key to success here. I’ll try to sketch my ideas. Could be a point to start. Maybe, when this thing gains some momentum, we could create an own github account for this where all shop modules are bundled and specific discussions on functionality can happen in the issues section. Who would be interested in contributing to a project like this?
- 69 replies
-
- 6
-
- e-commerce
- digital downloads
-
(and 2 more)
Tagged with:
-
A recent request of a client who we are porting (and in parts redesigning) a WordPress website to PW for, made me get into the eCommerce topic again–and lead me here again. I’m actually pretty sure one (or we?) could build a pretty powerful eCommerce framework on top of our beloved PW. Imagine an architecture that follows the principles and ideas of PW. Simple shop API (like $pages, $languages, $users you get $products or $shop in all your templates, etc.), completely modular: basic shop module as framework, implementing products page class, cart, checkout skeleton; more specific functionality is implemented through modules which hook into the framework (like a tax module would implement tax classes and be hooking into price calculations; payment modules would all hook into the checkout process the same way etc.). As soon as a basic shop framework would be available as a base module taking care of the basic stuff, developers could focus on very specific challenges (payment, stock management, etc.). I think I said it before: PW in my opinion misses two or three powerful modules/module packs that would open new doors two a broader adoption among web devs. One example is a really flexible eCommerce pack that turns PW into a shop/catalog, another is a easily customizable community pack with nice user management, registration, password recovery, log in stuff. Ah, and version management of course! Still, I wonder what today would be the best way to go if I wanted to build an online shop and embed/implement it in PW. Reading this thread made me shiver with fear!
- 69 replies
-
- 3
-
- e-commerce
- digital downloads
-
(and 2 more)
Tagged with:
-
I’ll push a little update for the plugin this weekend. I recommend we try again with the new files. Btw: You got some errors in your js, one because you wrote “jquery” instead of “jQuery”.
-
Could you update your remote setup so I can check? Thanks.
-
Thanks, Stefan. When I look at your code it seems to me, your initialization of responsiveImages isn’t executed on document.ready, what may cause the instance being not set up correctly. I repeated initialization via console after the page had been loaded completely. After doing this $('body').responsiveImages('getURL', ...) returned a path as expected. So I recommend to change your init code to something like this: /*-----------------------------------------------------------------------------------*/ /* RESPONSIVE IMGAGES PLUGIN */ /*-----------------------------------------------------------------------------------*/ $(function() { $('body').responsiveImages({ respondToResize: true, // if you want to load other image sizes on resize, respondToUpscaleOnly: true, // load other sizes only on upscale resolutionInterval: 50, // load image size of closest multiple of 50px (rendered 430px -> load 450px) imgSelector: 'img.adaptive', // if you want to be more selective, change it loadingClass: 'is-loading', // add a class to img while loading callOnUpdate: null, // optional callback when images are updated //callOnEach: null, //optional callback called for each images after loading callOnEach: function(image) { // http://stackoverflow.com/questions/21363955/get-each-image-natural-height-with-jquery var tempImage = new Image(); tempImage.src = image.attr('src'); var width = tempImage.naturalWidth; var height = tempImage.naturalHeight; image.attr('width', width); image.attr('height', height); var attribute = image.attr('data-original'); if (attribute) image.attr('data-original', image.attr('src')); }, debug: false // set to true to enable console output }); }); BTW: Responsive Images preloads images automatically. When callOnEach callback is called, the image has already been loaded. So you don’t need to create a new Image() and can access naturalHeight of the image directly to set the dimensions via html attributes.
-
So it returns null to newPath while url is logged with a seemingly correct value? Hard to tell from here. Could you load your setup up to server or make your local setup accessible somehow, so I can look into it?
-
Can’t say. Looks good so far. The thing is, that there is no case defined for getURL to return null. Could you log target.src and newPath to the console and post the results?
-
The way you call responsiveImages is invalid. On init the plugin only expects an object containing option settings. There is no path or target object to be set for responsiveImages. You just call it on an element of the DOM and the plugin takes care of all images contained in the element. If you want to keep going the way of assining an responsive image url to the current item, it should work like this: $('.product-gallery') .magnificPopup({ // ... callbacks: { change: function() { var pathname = this.currItem.src; // here you have to get the original image url, not window.location.pathname. You have to find out where it is stored. This is just a guess. var target = this.currItem; target.src = $('body').responsiveImages( // asuming you initiated responsiveImages on $('body') before 'getURL', pathname, { swidth: screen.width, pwidth: $(window).width(), pxratio: window.devicePixelRatio || 1 })); } } }); Because, if there is an instance set up, you can access some methods via $(element).responsiveImages(methodName, arg1, arg2, ...); like 'getURL'.
-
Try something like this: $('.product-gallery').magnificPopup({ // ... callbacks: { change: function() { var $container = $(this.contentContainer); $container.responsiveImages({ respondToResize: true, respondToUpscaleOnly: true, reset: true }); } } }); As far as I can see, you can access the content container created by Magnific Popup via this.contentContainer within its callbacks. That’s all you need. Responsive Images will find all img tags within and process them. If you want to just get a responsive image url for the current screen width from a normal image url, you can do it like: // As you need an instance of responsiveImages (you can use any you already have instanciated before) $('body').responsiveImages({...}); ... // get responsive image url from any image path var respImgUrl = $('body').responsivesImage('getURL', 'my/image/path.jpg', { swidth: screen.width, pwidth: screen.width, pxratio: window.devicePixelRatio || 1 }); // pxratio is optional here
-
Actually I wrote the plugin with cases like this in mind. When I started, there were no picture fill and the picture tag had still a far way to go. The good thing about my solution is, that you just have to upload the maximum resolution of an image. So you don’t have to create or even define any other image resolutions. In case you have dynamically generated parts like when using light boxes, popups and stuff, you just have to get your hands on the new/changed dom elements to call responsiveImages on. Magnific Popup provides several callbacks so you could do it like this: $('.image-link').magnificPopup({ type:'image', callbacks: { elementParse: function(item) { // Function will fire for each target element // "item.el" is a target DOM element (if present) // "item.src" is a source that you may modify var $container = $(item).parent(); // maybe you can instead access this.contentContainer, if the option is accessible from callback $container.responsiveImages({ ..., callOnUpdate: function() { // do what ever you want as soon as responsive images are loaded and sources are set }, reset: true // if an instance already exists on the element }); } } }); As I don’t know Magnific Popup, this may not be the best solution for it, but it should give you an idea how to deal with a case like this.
-
You can’t be sure. The URL called is correct. The rewrite rule in the .htaccess file should rewrite the request to the responsive-images.php. Be aware, that if the php script isn’t able to locate the original image file because of incorrect path settings, it also responds with a 404 Page Not Found error. Just to be sure, got to line $path = getPath($url); and add die($path); and then call the image url you posted above directly in the browser. If responsive-images.php is called, you should see the path of the original image.