Jump to content

qtguru

Members
  • Posts

    356
  • Joined

  • Last visited

  • Days Won

    5

Posts posted by qtguru

  1. Twig doesn't know what a field is, all it expects are variables which are passed to the twig templates from the processwire php files based on the Twig module. Let's take for example the side template in twig, I can have an array of posts which will render the post in a list manner. All I simply need to do is get a list of post and set it with a variable name for that template and the twig template simply renders it based on the variable passed. Besides at the end of the day Twig is basically still compiles to php so it's nothing unique just another layer. 

  2. 6 hours ago, tpr said:

    I'm not using twig but latte but the main advantages are sophisticated template inheritence, filters, reusable blocks/partials, etc, and after all, more readable and maintainable code. Backdraws are the small overhead and some extra complexity, of course the latter disappears when you get used to it.

    Markup regions is in my opinion a very simple templating implementation. This works fine if you don't need any of those extra features, and in case of template engines you can more easily find help if you are stuck.

    Speaking of myself, I made only my first PW project with pure PHP about 3 years ago, then all with latte.

    I just looked at Latte and it's very clean to read, it looks so similar to Twig, I was using Smarty before but Twig is 100% OOP and extending it is cleaner compared to Smarty, I will give Natte Latte a shot later on. 

    • Like 1
  3. 6 hours ago, pideluxe said:

    Pls tell us, what is the advantage of twig templating over pure php and using the delayed output strategy with markup regions?

    "delayed output strategy" to me is the same as concatenation, it easily gets messy, hard and difficult to follow, not exactly easy to inherit templates or layouts.

    It might work but it comes at the cost of readability and how easy it is in making mistakes.

     Twig Template makes it easier to read ,the only disadvantage I can bring up is that, you cannot instantiate a class inside the template, you must pass a reference of an object to it, then again, your template must not be tied to a code, it should simply take a value it expects and evaluate from that. It makes things really easy to read. 

    As for performance it compiles down to php templates, it only compiles when the source has been changed. 

     

  4. On 3/18/2018 at 9:10 PM, cmscritic said:

    I've got too many sites now that I need to be able to manage them all (my wife's included) from a single dashboard (since most are WP) and I've also got a number of WP clients I look after so I went 100% WP across the board. Nothing to do with PW, which served me wonderfully for a long long time.

    I understand what you mean, I had the opportunity to rewrite an existing application to Processwire, that was going to be alot of work plus the site works fine already, as I know my way around WordPress Development, sometimes some decisions are not technical just business sense. 

    • Like 1
  5. Hi, So today I will writing a small tutorial on developing templates in Processwire using Twig Template, Processwire is a highly flexible CMS which gives developers/designers/users options and allows easy extension of the platform. So here goes the tutorial 

    What is Twig Template ?

    Simply put in my own words, Twig is a modern templating engine that compiles down to PHP code, unlike PHP, Twig is clean on the eyes , flexible and also quite *easy* to have dynamic layout site with ease ,without pulling your hair out. Twig is trusted by various platforms. It was created by the guys behind Symfony.

    Take this code as an example

    {% for user in users %}
        <h1>* {{ user }}</h1>
    {% endfor %}

    This will simply be the equivalent in PHP World

    <?php
    
    $userArray = ["Nigeria","Russia"];
    
    foreach($userArray as $user):
    ?>
    <h1><?= $user ?></h1>
    <?php
    endforeach;

    The PHP code though looks simple enough however, you start to notice that you have to be concerned about the PHP tags by ensuring they are closed  properly , most times projects gets bigger and comes complex and harder to read/grasp, and also in PHP you can explicitly create variables in the template making it very hard to read as it grows and prone to getting messy WordPress is a major culprit when it comes to that regard.

    Have you ever wanted to created separate layouts for different pages and  break your sites into different parts e.g Sidebar, Comment Section, Header Section ? the regular approach would be to create individual pages for each section and simply add them as templates for the pages and with time, you can end up having tons of templates, however Twig allows you to easily inherit templates and also override the templates where you can inject content into the block easily. Don't worry if you don't understand the concept, the following parts will explain with an example of how to easily inherit layouts and templates.

    Layout

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
       {{include("layout/elements/header.twig")}}
    </head>
    
    <body>
     
        <div class="container-fluid" id="minimal">
            <header id="pageIntro">
                <div class="bio_panel">
                    <div class="bio_section col-md-6">
                        <h1>Okeowo Aderemi</h1>
                        <h2>{{ page.body }}</h2>
                    </div>
                </div>
                <div class="clearfix"></div>
    
    
            </header>
            <section id="page-body">
                <div class="container">
                    <div id="intro" class="col-md-7 col-lg-7">
                        <h1>About me</h1>
                        <h2>
                            {{ page.summary }}
                        </h2>
                    </div>
                  {block name="content"}{/block}
                 
                        <a style="font-size:1.799783em; font-style:italic;color:#d29c23" href="{{pages.get('/notes').url }}">Read more articles</a>
                    </div>
                    <div class="clearfix"></div>
                </div>
    
            </section>
    
        </div>
        <footer>
            <div class="header-container headroom headroom--not-top headroom--pinned" id="header-container">
    
       {{include("layout/elements/footer.twig")}}           
    
            </div>
        </footer>
    </body>
    
    </html>

    This is basically a layout where we specify blocks and include other templates for the page, don't panic if you don't understand what is going on, I will simply break down the weird part as follows:

    Include

    This basically is similar to native PHP 'include', as it's name suggests it simply includes the templates and injects the content into the layout , nothing out of the ordinary here if you are already familiar with php's include function.

    {{ output }}

    This simply evaluates the expression and prints the value, this  evaluate expressions, functions that return contents , in my own short words it's basically the same as <?= output ?> except for the fact that it's cleaner to read.

    {% expression %}

    unlike the previous this executes statements such as for loops and other Twig statements.

    {% for characters in attack_on_titans %}
    <h1> {{characters}} </h1>
                    {% endfor %}

    This  executes a for loop and within the for loop, it creates a context to which variables in that context can be referenced and evaluated, unlike dealing with the opening and closing PHP tags, Twig simply blends in with markup and makes it really quick to read. 

    I will simply post the contents of both the header and footer so you can see the content of what is included in the layout

    header.php

    <meta charset="utf-8"/>
    <meta content="IE=edge" http-equiv="X-UA-Compatible"/>
    <meta content="width=device-width, initial-scale=1" name="viewport"/>
    <title>
        {{ page.title }}
    </title>
    <link href=" {{config.urls.templates }}assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="{{config.urls.templates }}assets/css/main.min.css" rel="stylesheet"/>
    <link rel='stylesheet' type='text/css' href='{{config.urls.FieldtypeComments}}comments.css' />
    <link rel="stylesheet" href="{{config.urls.siteModules}}InputfieldCKEditor/plugins/codesnippet/lib/highlight/styles/vs.css">
    <script type="text/javascript" src="{{config.urls.siteModules}}InputfieldCKEditor/plugins/codesnippet/lib/highlight/highlight.pack.js"></script>
    
    <script src="{{config.urls.templates }}assets/js/vendors/jquery-1.11.3.min.js">
    </script>
    <script src="{{config.urls.templates }}assets/js/vendors/bootstrap.min.js">
    </script>
    <script src="{{config.urls.FieldtypeComments}}comments.js"></script>
    <link rel="stylesheet" type='text/css' href="{{config.urls.templates}}js/jquery.fancybox.min.css">
     <script src="{{config.urls.templates}}js/jquery.fancybox.min.js"></script>
     {block name="javascriptcodes"}{/block}

    footer.php

     <nav class="site-nav pull-right">
                    <div class="trigger">
                        <a class="page-link" href="{{pages.get('/about').url}}">
                            <span>{</span> About
                            <span>}</span>
                        </a>
                        <a class="page-link" href="{{pages.get('/notes').url}}">
                            <span>{</span> Journals
                            <span>}</span>
                        </a>
                   
                        <a class="page-link" target="_blank" href="https://ng.linkedin.com/in/okeowo-aderemi-82b75730">
                            <span>{</span> Linkedin
                            <span>}</span>
                        </a>
                        <a class="twitter page-link" target="_blank" href="https://twitter.com/qtguru">
                            <span>{</span> Twitter
                            <span>}</span>
    
                        </a>
                    </div>
                </nav>

    There's nothing special here, other than twig simply injecting these fragments into the main layout , the next part is the most interesting and important concept and benefit that Twig has to offer

    {% block content %}{% endblock %}

    This tag simply creates a placeholder in which the content would be provided by the template inheriting this layout, in lay terms it simply means child templates will provide content for that block, the 'content' simply uses the name 'content' to refer to that specific block, so assuming we were to inherit this template it would simply look like this.

    Inheriting Template Layout

    {% extends 'layout/blog.twig' %}
    {% block content %}
    <div class="container blog-container">
        <section class="blog">
            <header class="blog-header">
                <h1>
                    {{page.title}}
                </h1>
                <h5 class="blog_date">
                    {{page.published|date("F d, Y")}} 
                </h5>
                <br>
                </br>
            </header>
            <div class="blog_content">
                <hr class="small" />
                 {{page.body}}
                 <hr class="small" />
    
            </div>
        </section>
    </div>
    {% endblock %}
    
    {% block nav %}
     <div class="col-md-4 col-xs-4 col-sm-4 prev-nav">
                            <a href="{{page.prev.url}}">
                                ← Prev
                            </a>
                        </div>
                        <div class="col-md-4 col-xs-4 col-sm-4 home-nav">
                            <a href="{{homepage.url}}">
                                Home
                            </a>
                        </div>
                        <div class="col-md-4 col-xs-4 col-sm-4 next-nav">
                            <a href="{{page.next.url}}">
                                Next →
                            </a>
                        </div>
    {% endblock %}

    In this snippet you can easily notice how each blocks previously created in the header and layout are simply referenced by their names, by now you will notice that twig doesn't care how you arrange the order of each block, all Twig does is to get the contents for each blocks in the child templates and inject them in the layout theme, this allows flexible templating and also extending other layouts with ease.

    Twig in Processwire

    Thanks to @Wanze we have a Twig Module for Processwire and it's currently what i use to build PW solutions to clients

    https://modules.processwire.com/modules/template-engine-twig/

    The Modules makes it easy to not only use Twig in PW but also specify folders to which it reads the twig templates, and also injects Processwire objects into it, which is why i can easily make reference to the Pages object, another useful feature in this module is that you can use your existing template files to serve as the data provider which will supply the data to be used for twig template.

    take for example, assuming I wanted the homepage to display the top six blog posts on it, TemplateEngineTwig will simply load the home.php ( Depending on what you set as the template), it is also important that your twig file bears the same name as your template name e.g home.php will render into home.twig here is an example to further explain my point.

    home.php

    <?php
     
      //Get the Top 6 Blog Posts
      $found=$pages->find("limit=6,include=hidden,template=blog-post,sort=-blog_date");
      $view->set("posts",$found);

     

    The $view variable is the TemplateEngine which in this case would be Twig, the set method simply creates a variables posts which holds the data of the blog posts, the method allows our template 'blog.twig' to simply reference the 'posts' variable in Twig Context. Here is the content of the 'blog.twig' template

    blog.tpl

    {% extends 'layout/blog.twig' %}
    {% block content %}
       <div class="block_articles col-md-5 col-lg-5">
                        {% for post in posts %}
                        <div class="article_listing">
                            <span class="article_date"> {{post.published}}</span>
                            <h2 class="article_title">
                                <a href="{{post.url}}">{{post.title}}</a>
                            </h2>
                        </div>
    		{% endfor %}
    {% endblock %}

    So home.php sets the data to be used in home.tpl once Twig processes the templates and generates the output, twig takes the output from the block and injects it in the appriopriate block in the layout, this makes Processwire templating more flexible and fun to work with. 

    The major advantage this has; is that you can easily inherit layouts and provide contents for them with ease, without the need of running into confusions when handling complex layout issues,an example could be providing an administrator dashboard for users on the template side without allowing users into the Processwire back-end. You can also come up with several layouts and reusable templates.

     

    Feel free to ask questions and any concerns  in this approach or any errors I might have made or overlooked.

    Thanks

     

     

     

    • Like 20
    • Thanks 2
  6. 1 hour ago, louisstephens said:

    You can achieve something (that I think is better) using a the Repeater Matrix (profield). I was actually playing with this the other day. I created several "blocks" ie image/text, quotes, slideshow etc etc and with very little effort (output styling not included) had a homepage built.

    5a9ed252b1a15_ScreenShot2018-03-06at12_38_57PM.thumb.png.12c675b357567da445864797eaf6cff7.png

     

    I like this approach better than Visual Builder as it allows the developer to have a bit more control of the output (styles/layout). In my experience, vb can lead to bloat, and a very fractured site structure. It also, at times, makes it difficult to find where pieces of the site are located.

    The correct word is all times, I haven't come across any site builder that allows 100% control over content without creating a mess or even without the need for code, the closest so far I can think of is October CMS which generates a templates from the frontend and allows you to tweak them, but it requires knowledge of Twig or blade (not sure), really this is an important topic you raised, I have a client i tried convincing to try Processwire, but the client wasn't interested in coding and wanted to builder to achieve all their needs. The only thing i can think of is a Builder 100% built around Processwire API(s) meaning, when they create a Page and add content and use modules from builder, at the backend it should replicate the same process like creating a template, downloading the modules but that will be a very difficult task to achieve. However I would be happy to hear what ideas you have and we can research further upon that. so far Processwire is the best CMS platform that's minimal and straight forward but for developers more.

    ImpressPages comes close to what you have in mind, I will keep an eye on this thread and contribute should i have more information. If this can be achieved I think we can further push PW to clients and have them replace WordPress, at the same time we should be careful we don't create another WordPress in this ecosystem. what do you think ? 

    • Like 3
  7. 18 hours ago, pwired said:

    Hi Sephiroth

    Did you try net2ftp, monsta ftp and cpanel proxy urls at the office ?

    Net2FTP logs me out everytime, I feel it must be network related haven't tried monsta FTP but i like the having to just edit the file from the same application however it should only edit the modules and templates and not core code. 

    • Like 1
  8. On 1/7/2018 at 4:48 PM, matjazp said:

    Yes, CodeMirror and, later maybe monaco (PR's welcome).

    Am looking at that too, I will fork your project over the weekend and see how I can contribute, am really interested in this, though I have a feeling Monaco feels like overkill, but i will evaluate it and see.

     

  9. 17 hours ago, matjazp said:

    A module for managing files and folders. Supports creating, opening (e.g. viewing, playing, editing), renaming, moving, copying, deleting and searching for files. You can also view and change (not supported on Windows) file and directory permissions. 

    https://github.com/matjazpotocnik/ProcessFileManager

    Screenshot 2018-01-06 20.06.44_cr.jpg

    The author of FileManager component is (c) 2006 - 2018 Gerd Tentler, http://www.gerd-tentler.de/tools/filemanager/. I modified it to work with ProcessWire as a module. Please see license files on usage in commercial projects!

    This would be the most useful module for me, because I tend to do my sidejobs at the office after work (I know, it's not proper, commuting issues that's why ) and we have a strong Firewall that blocks FTP and CPanel pages, so this will come real handy, am assuming it has a code-editor in it. thanks a bunch.  

    • Like 1
  10. On 31/12/2017 at 8:07 PM, blynx said:

    Hm, if you view a WordPress frontend with populated data and copy/paste the source you have more or less an HTML theme?
    Apart from that, there will still be manual work.

    Yeah alot of manual work, sometimes it's hard because you need to know which file isn't wordpress specific as it's massive and populated. 

  11. This is not just another developer survey.

    Are you ready for the most global developer survey, designed by developers for developers? The Developer Economics Q4 2017 survey is here and for its 14th edition,aiming at sheding light to the future of the software industry! Every year more than 40,000 developers around the world and participate in this survey, so this is a chance to be part of something big, voice your thoughts and make your own contribution to the developer community.

    Is this survey for me?

    The survey is for all developers engaging in the following software development areas: Mobile, Desktop, IoT, AR/VR, Machine Learning & Data Science, Web, Backend and Gaming.

    Do you want to go to the survey now?

    What questions am i likely to be asked?

    As always the survey is looking to shed lights to questions about the current status and the future of the software industry.

    • What’s going up and what’s going down in the software industry?
    • Are you working on the projects you would like to work on?
    • Where do you think development time should be invested?
    • Which are your favourite tools and platforms?

    Remember your opinion matters, so answers to these questions can be entirely  shaped by you and your fellow developers!

    Developer goodies

    There are some perks to go with your participation. Have a look at what you can get our hands on:

    • Amazing prizes up for grabs:  a Pixel 2 phone,  an iPhone X,  a Windows Acer MR headset, a Nintendo Switch,  Raspberry Pi 3’s  and more
    • A Developer Scorecard showing responses from developers in your region
    • A free State of the Developer Nation Q1, 2018 report with the key findings (February 2018).
    • A referral program you can join, promote the survey and win up to $700 in cash!

    If Cyberpunk is your thing, you will love it!

    Always designed with an extra fun factor, the Developer Economics Survey shares a CyberPunk theme for its 14th edition.Taking the survey means that you will get to find out if you are a Cyber-Cultist, a Scale-O-Fixer or a Console Boy among others  Have a look at the full list of characters.

    Sounds exciting right?  So why don’t you take the survey right away?

    http://vmob.me/DE4Q17oa1ng?fl=en

     

  12. On 11/12/2017 at 8:16 PM, clsource said:

    The only benefit of Laravel (And other PHP Frameworks) is they can interact with the ProcessWire API directly (Using composer and namespaces). But that can easily be solved with a simple Rest APi although requires more work

    The Benefit of Framework is standardized way of working take for example we use Processwire I know if i need to make a DB call i'd use the Processwire DB Class, that already saves us the stress of trying to understand each other's code since there's already a standard and way, now imagine you were to manage a non-framework project you'd find yourself trying to understand the way it works and also how it works. That's way framework come in, and also best practices also 

    • Like 2
  13. On 12/10/2017 at 9:56 AM, szabesz said:

    https://processwire.com/talk/topic/17707-php-in-2017-rasmus-lerdorf-wearedevelopers-conference-2017/

    You might want to watch it from 02:42
    PHP was meant to be a templating language only (which it is still today) on top of the business logic written in C but as it turned out, nobody wanted to write and compile C.

    Sure, these days we have better alternatives when it comes to writing code that can be compiled to machine code but it still requires a lot more setup an configuration than to simply use PHP or Perl which are preinstalled on each webserver, ready to be used by writing a few lines of code or installing a CMS or framework in a few minutes. PHP is evolving and it is still a solid option for small or medium sized solutions and I guess 95% of the web belongs to those categories.

    Sure, when one is after a career of writing code for big companies (including big governments), PHP might not be the best language to practice. However, freelancers and small companies can still rely solely on PHP as far as running code on the server is concerned.

    Hi regardless remember I come from a Third world country,small customers cannot simply afford employing developer of other languages and PHP is quite affordable so far PHP has a market, PHP is still viable and in demand, I was just approaching it on the basis that other compiled language would outperform PHP doesn't mean PHP is irrelevant also I don't have any preference for any language I pick whatever works but i must admit PHP is the only platform that's faster for me to bootstrap and come up with something within a short time. 

     

    On 12/10/2017 at 11:51 AM, SamC said:

    One ‘issue’ I would say for me learning processwire so far is that I’m not sure how much actual php I’ve learnt. My logic skills have certainly improved, I can see that, but as far as getting a Job as a junior dev with js/php I feel like I’m still so far away! Round here they list requirements that read to me like the requirements for a very experienced dev, not stuff that I’d call “junior”.

    To be frank most companies as long as you know PHP to a certain level and you are willing to learn, companies would employ you, there was a time I wasn't familiar with frameworks till I worked for a company and was given a project, I was given a PHP Book on Advanced PHP Development, However the fastest way to pick up PHP is to look up PHP the Right Way.  I would have loved to recommend Symfony Framework, I work for an enterprise organization and we mostly develop in almost any language except PHP but mostly Java Spring Framework and Symfony feels closer to that, Symfony gives so much flexibility and freedom and uses best practice, unlike Laravel, I have issues with the abuse of Static class and some Classes suffer from what I call "God Object", The Eloquent ORM irks me out it has too much logic compared to Doctrine way's of handling data. Here is another good resource for PHP knpuniversity.com, Just take it one day at a time.

     

    On 12/10/2017 at 2:38 PM, tpr said:

    I agree that if there's no project to start using a new tool can be frustrating. I usually decide what to learn and during the learning process a project usually comes to my mind that could be created/rewritten in it, or at least more fun.

    Exactly

    • Like 1
  14. On 11/10/2017 at 6:37 PM, LostKobrakai said:

    I'm currently in a full on switch away from php to elixir, but I'd still not say php is generally bad. For websites with none or some business logic involved it's certainly good enough and has lot's of tools/people for moving quickly in that space. But I'd no longer use it for anything more complex or custom made. 

    The things, which drew me to switch over where actually not the language per se, but rather the environment: Elixir is a compiled language, which is way more performant than php. It's damn easy to do concurrent computation harnessing the power of multi-core cpus, which is just a pain in php (react-php or threading). Long running computations are hard to do in a php world, where 98% of the time each request starts/terminates the whole world. Sure one can start a php script in the cli, but it's the communication which is the annoying part. Websockets or http2 streaming are the things in the web world, which are only possible with long running processes. 

    Elixir does come with a own testing framework within the language. Code documentation is first-class citizen and the community/package manager push people actively to use it e.g. with automatic documentation hosting for packages. So there's a kinda canonical place for documentation and hell can it be good for the more popular packages. In PHP there's not even real consensus about using composer.

    And the final point is that a functional language with immutable data does now fit my mind way better than oop and shared memory.

    Exactly you've hit the nail with the shortcoming of PHP, it's interpreted every time it needs to be parsed and fed to the Zend Engine meanwhile compiled languages would run much more faster and scale better than PHP, I read the benchmark of a Golang application and I was blown apart normally i'd stick to Spring but the memory consumption is excess, but I haven't come across elixir, might give it a shot

  15. If you are doing Web PHP is still awesome, however if it reaches the point where you are really taking shit load of request, that's when you will branch to faster languages like Golang, For me am still deciding which to commit to still deciding between .NET Core, Spring MVC or Golang Web frameworks but still be using PHP for simple sites. 

  16. I have done something like this but this was in Spring Framework and not Processwire, you don't really need fields to do this ( This is my issue with using PW,it's easier for me to translate logic to classes than fields and pages).

     

    What i did was to create different Object in Java and created an interface to make things easier so you have your MultiChoice Class, True or False Class, Open End Question class , all i needed to do was return a JSON that had enough meta-data to inform the UI what to render on the frontend and based on the question type it would generate the control to display the question and save the answer to a QuizManager which stores the question id and the answer for each quiz.

  17. I have heard alot about Django from a mentor, from what I hear it's actually quite a robust solution, so to be honest am a fan of use what's right , I don't subscribe to using Processwire for every type of application most times, I might find myself using Symfony for certain projects because of the flexibility and proper architecture that requires me to handle things and remove certain bundles , but I mostly use Processwire to build sites I want clients to manage, the moment an application has so many custom and specific needs, I would use an application framework, now if I were in Python world, because I don't really like Python i'd use Django for Site management but would prefer to use something light and flexible. 

     

    Also I think you should state views without insulting, calling people "Fanboy" is not the right approach all the best 

    • Like 5
    • Thanks 1
  18. This is strange I can't find myself to hooking TemplateEngineTwig:init no matter what i do nothing happens and in Symfony this is not a problem for me, am I missing anything

     

    wire()->addHookAfter("TemplateEngineTwig::initTwig", function($event) {
    	$twig = $event->arguments('twig');
    	$instanceOfFunction = new Twig_Function('instanceof', function ($object,$evaluatedClass) {
    		return ($object instanceof $evaluatedClass);
    	});
    	$twig->addFunction($instanceOfFunction);
      });

     

  19. 7 hours ago, heldercervantes said:

    Just tried out the latest dev version and experienced the new admin area.

    Damn, this is a beautiful CMS. Can't wait to see how my clients react to this.

    *Runs to update and try new version out* the day just got better

    • Like 4
×
×
  • Create New...