Jump to content

stanoliver

Members
  • Content Count

    24
  • Joined

  • Last visited

Posts posted by stanoliver


  1. @dragan Your question made sense I am sorry for confusement.

    Actually the real templates are like:

    - templatehome.php

    - templatebasicpage.php

    The templates "templatetoparea.php" and "templatefooterarea.php" are included/are partials.

    The template "mainarea.pp" made no sense at all. Sorry for confusing you.

    Thanks for your help so far I will try out your guys hints.


  2. @draganWell, I did not say that php is worthless because is one of the most used programming languages out there and it runs in a simple shared host enviroment.

    Have a look at the elegance of languages like elixir, julia, ruby or even pyton then you will know why I consider php a mess. Php is the same mess as javascript  even when both languages are used heavily.

    If python, julia or elixir would run in simple shared host enviroments for a 3-4 Euros a month then there would be no need for php anymore.


  3. Hi! I tried to implement a simple site search like in the regular site profile by Ryan.

    http://demo.processwire.com/regular/

    I checked out the code on github but I could not make it work for my site. Probably because Ryan uses some advanced output strategy and uikit specific stuff which I don't use or understand.

    For my site I just use:

    - 1 template (name: templatetoparea.php) for the toparea of my site

    - 1 template (name: templatemainare.php) for the main content of my site

    - 1 template (name: templatefooterarea.php) for the footerarea of my site.

    Also I have prepared two empty templates:

    - 1 template (name: templatesearch.php) for the search itself

    - 1 template (name: templatelistsearch.php) for listing the search results

    May somebody could let me know how to implement a very basic site search like in the regular site profile without using any module or complicated output strategies.

    Two things would be a must have:

    - The search should work with standard repeaters (where most of my content lives)

    - The search results/hits should be listed and the search word(s) should have a yellow colored background (inline css is fine) 


  4. Hi! 

    The following code snippet is part of my markup simple navigation and the url_redirect (url field in the backend) just works fine when I put an special custom url into the url_redirect field.

    <?php
                $nav = $modules->get("MarkupSimpleNavigation");
                
                
                
                // topnav
                $current = $page->rootParent(); // current root page
                
                
                // subnav
                echo $nav->render(array(
                    'max_levels' => 2,
                    'item_tpl' => '<h4><a class="g8-bar-item g8-hover-black" href="{url_redirect|url}">{title}</a></h4><hr class="sidenav">',
                    'collapsed' => true,
                  ), $page, $current);
                ?>

     In my seperated breadcrumb navigation I use the following code snippet

    <?php
                                      
                                      foreach($page->parents()->append($page) as $parent) {
                                      
                                          echo "<li><a href='{$parent->url_redirect|url}'>{$parent->title}</a></li>";
                                      
                                      }
                                      ?>

    Now to the problem: In my first code snippet above the

    url_redirect|url 

    works just fine but when I try something similiar in the second code snippet

    $parent->url_redirect|url

    I produce an server error How do I have to change the second code snippet so that it works in the correct way as the first code snippet does?


  5. Hi @MoritzLost your provided examples just work great. Two little things I still have not found out yet:

    1. In the backend I created a simple text field named "datarow". In my php-template I wanna use your example 

    $prices = [
    	'100', '200', '300', '400', '500'
    ];
    
    foreach ($prices as $price) {
        echo $price . ' ';
    }
    

    which just works fine. How do I have to change the code of your example if I want everything between the [ ] to be my field "datarow"? How to change the foreach?

    With repeating a lot of code I would do something like:
     

    $prices = [ '100', '200', '300', '400', '500' ];  // 
    
    $prices2 = [ '500', '400', '300', '4040', '5400' ];

    Desired output would be something like (no comes pseudocode) on a normal processwire page:

    foreach start
    
    $prices = [ datarow ]; // datarow ist the created simple textfield which should be editable by an enduser
    
    foreach end

    I tried something like 

    <?php
    echo $prices=[<?= $page->datarow ?>] ;
    ?>

    which could not work because nested php-code throws errors and the foreach is not even implemented.


  6. @Soma Just wanna let you know that no help needed anymore because it probably was a wrong right management between admin role and another custom role I have. Everything seems to work fine.


  7. @louisstephens Yes, your examples already helps. Do you know if the xml-syntax would also work with the new page meta or does page meta need json-syntax

    Basicly I just looking for comfortable ways/ideas how to get data (even better data rows) out of html tables, csv-files, xml-files etc. and vice verca for outputting them in the frontend. Let's say I have a row in a csv-file with the entries '100','200','300' (representing prices: '100'->first price ...)

    At last coming back to your example from above: How would I need to change your code from above to get an export to an .csv-file?


  8. My aim is to output a very basic xml document which should be styled with a few css-styles.

    <?xml version = "1.0"?>
    <contact-info>
       <name>Donal Duck</name>
       <company>Superducks</company>
       <phone>(011) 123-4567</phone>
    </contact-info>

    How do I implement it with processwire?


  9. @Soma Could you may help me with your module? I created a field color1 for all my headlines (h1-h6) setting its default color to #550000. The output in the frontend shows nicely the default color I have set. If I set any other default color everything still works fine.

    The problem is: If I pick with the color-picker another color (does not matter which color) just nothing happens. It still shows the default color which is set. Are there maybe any special extra settings to allow the overwrite of the default color?


  10. @dragan Probably you misunderstood me. 

    The first row in my spreadsheet is just the names/titles of the cars:  'car1','car2',..., 'car5'

    The second row will show the PS (Powerhorses) of my cars: '100','200','300','400','500'

    So 5 columns and 1 row is totally fine.

    A foreach loop with an icrement will work but is there no shorter/more comfortable way possible at least if my amount of cars (5 columns) will be fixed.

    Something like in my own "pseudo-Code": 

    echo $carps[0-4];

    which would output the ps of the first car, then the ps of the second car and so on ...


  11. @MoritzLost and @szabes First thanks for your additions. Do you guys may have an elegant solution for a  related situation?

    Let's asume I have 5 cars in an excel-like-spreadsheet.

    Further I have a two rows in a datatable

    car1     car2   car3   car4    car5

    100      200    300   400     500      (Powerhorses/PS)

    If I would like to export the data out of my example above to a csv-file the data in the csv-file may look like

    "car1";"car2";"car3";"car4";"car5";

    "100";"200";"300";"400";"500";

    The syntax of the array declaration

    $colors = [
    	'red',
    	'green',
    	'blue',
    ];

    and syntax of my spreadsheet data looks quite similiar. I would be even more similiar if my csv would look like:

    'car1','car2','car3','car4','car5'

    '100','200','300','400','500'

    and therefore I could just copy-paste a raw of my csv-file so that I could become an array declaration like:

    $price = [
    	'100','200','300','400','500'
    ];

    So the array declaration could be simple done by copy pasting out of my csv file.

    Now to the problem: Are their ways to adjust the working syntax/code 

    echo $carps[0];
    echo $carps[1];
    echo $carps[2];
    echo $carps[3];
    echo $carps[4];

    by a loop or also without a loop so that the whole array gets output at once without repeating myself 4 more times.

    Also it would be important that the adjusted code leaves a possibilty styling the output with some css.

     


  12. 15 hours ago, Robin S said:

    Another way that you might be connecting categories to posts is by a parent-child relationship. So the post pages are children of a category page that they belong to. This is okay but less flexible because it means that any post can only belong to one category. So if you found yourself needing to write a blog post "How to fix a bike rack to your car" you would have a problem because the post could only be in the bike category or the car category but not both.

    But if you are in fact using a parent-child relationship you would use this selector on the category page (note change from $pages->find to $page->children):

    
    $results = $page->children("template=templateblogpost, limit=5, sort=-postdate");

     

    @Robin S 1. Yes, I am using a parent-child relationship and for the moment it would be enough even when a post can only be in one category.

    2. The little snippet of Gideon

    if($page->path == "/categories/cars/") {
    
    Do your thing here.
    
    }

    is already totally fine and I do not need much more functionality. I only would need something like in (my own pseudocode comes now):

    if($page->path == "/categories/$variable/") {
    
    echo $variable->title;
    
    }
    

    If the url is

    /categories/cars

    the output should be all posts in category cars.

    If the url is

    /categories/airplanes

    the output should be all posts in category airplanes

    3. There would be no problem at all with all my mentioned code above if I only knew which are categories I will need in the future but I don't know that becaus the end user will be allowed to drop new childrend under the parent "categories"

     


  13. Important: Using following selector works just perfect in my codeblock (xxx)

    $results = $pages->find('id>1, template=templateblogpost, category=cars, limit=5, sort=-postdate'

    and when I  go on repeating another codeblock with

    $results = $pages->find('id>1, template=templateblogpost, category=airplanes, limit=5, sort=-postdate'

    and the last codeblock with

    $results = $pages->find('id>1, template=templateblogpost, category=motorcyles, limit=5, sort=-postdate'

    all just works fine.

     

    So one entire codeblock (xxx) wich just works perfect looks like:

    <?php foreach ( $results = $pages->find('id>1, template=templateblogpost, category=cars, limit=5, sort=-postdate') as $post 😞?>
    <!-- Blog entry -->
    <div class="g8-card-4 g8-margin g8-white">
    <!--<img src="/g8images/bridge.jpg" alt="Norway" style="width:100%">-->
    <div class="g8-container">
    <h3><b><?= $post->title; ?></b></h3>
    <h5>Datum: <span class="g8-opacity"><?= $post->postdate; ?></span></h5>
    </div>
     
    <div class="g8-container">
    <p><?= $post->posteditor; ?></p>
    <div class="g8-row">
    <div class="g8-col m8 s12">
    <p>
    <a href="<?= $post->url; ?>"><button class="g8-button g8-padding-large g8-white g8-border"><b>Details lesen »</b></button></a>
    </p>
    </div>
    <div class="g8-col m4 g8-hide-small">
    <!--<p><span class="g8-padding-large g8-right"><b>Comments  </b> <span class="g8-badge">2</span></span></p>-->
    </div>
    </div>
    </div>
    </div>
    <!-- END BLOG ENTRIES -->
    <?php endforeach; ?>
     
    <? echo $results->renderPager(array(
    'nextItemLabel' => "back",
    'previousItemLabel' => "forward")); ?>

    I also could use  the last codeblock (xxx) two more times and just replace in the "first line" "category=cars" by "category=airplanes". Another time (the third codeblock) would be identical and I only would replace "category=cars" by "category=motorcyles". Then I would have 3times an almost identical codeblock which only differs in one place: "category= " Repeating almost identical code is a bad habbit and therefore I need a variable like $segment so that I just can make everything work with one codeblock.

    Maybe short in other words:

    Before I can use something like $segment in my codeblock (xxx) I have to declare it before my block starts but I have no idea how to declare $segment. What I know is that my codeblock (xxx) works perfectly for a specific category.


  14. @Robin S What already work is (but only with repeating 3times almost identical code):

    <?php foreach ( $results = $pages->find('id>1, template=templateblogpost, category=cars, limit=5, sort=-postdate') as $post ?>
    
    do something
    
    <?php endforeach?>
    
    //////////////////////////////////////
    
    <?php foreach ( $results = $pages->find('id>1, template=templateblogpost, category=airplanes, limit=5, sort=-postdate') as $post ?>
    
    do something
    
    <?php endforeach?>
    
    ////////////////////////////////////////
    
    <?php foreach ( $results = $pages->find('id>1, template=templateblogpost, category=motorbikes, limit=5, sort=-postdate') as $post ?>
    
    do something
    
    <?php endforeach?>

    What I would like to have:

    Only one time the codeblock

    <?php foreach ( $results = $pages->find('id>1, template=templateblogpost, category=$segment, limit=5, sort=-postdate') as $post ?>
    
    do something
    
    <?php endforeach?>

    The problem is that I do not know what's the code related to $segment before the opening of <?php foreach ... ?>

    I could imagine something like 

    (*****)
    
    if($segment->path == "/categories/segment/") {
    
    <?php foreach ( $results = $pages->find('id>1, template=templateblogpost, category=$segment, limit=5, sort=-postdate') as $post ?>
    
    do something
    
    <?php endforeach?>
    
    }

    In short: 

    1. The code should check in the url wich category is used and assign the variable $segment to it 

    2. The code above (*****) should be executed with the right $segment


  15. On 11/13/2012 at 6:37 PM, diogo said:

    just an example:

    
    <style>
    body{
      background-color: <?=$page->backColor?>;
    }
    </style>
    
     

    May someone could help me.

    In the pw backend I have the following hierarchy:

    /tools/

    /tools/colorpicker/

    /tools/colorpicker/maincolor1/

    /tools/colorpicker/maincolor2/

    /tools/colorpicker/maincolor3/

    etc.

    maincolor1, maincolor2, maincolor3 should only set 3 different colors for just a simple <h1>heading</h1> customized with css. My only problem is to use the right selectors in the right way so that the work probably with the module. The datepicker module itself is in the backend installed and works.

    At last I am not sure if the following snippet is needed at all or only when I use an external css-stylesheet and I have not sure where I should place it:

    The snippet 

    <?php header("Content-type: text/css"); ?>

    May someone could tell me where to put everything in the right place so that I can set the color of my three headings by the colorpicker module.


  16. @Gideon So Hi Gideon, if I use the code you provided and replace "Do your thing here."

    with echo 'Hi!';

    everything works but I need that code work togehter with my code from above. My own code from above works also perfectly but I do not want to repeat myself in way like:

    <?php foreach ( $results = $pages->find('id>1, template=templateblogpost, category=cars, limit=5, sort=-postdate') as $post ?>
    <!-- Blog entry -->
    <div class="g8-card-4 g8-margin g8-white">
    <!--<img src="/g8images/bridge.jpg" alt="Norway" style="width:100%">-->
    <div class="g8-container">
    <h3><b><?= $post->title; ?></b></h3>
    <h5>Datum: <span class="g8-opacity"><?= $post->postdate; ?></span></h5>
    </div>

     

    <div class="g8-container">
    <p><?= $post->posteditor; ?></p>
    <div class="g8-row">
    <div class="g8-col m8 s12">
    <p>
    <a href="<?= $post->url; ?>"><button class="g8-button g8-padding-large g8-white g8-border"><b>Details lesen &raquo;</b></button></a>
    </p>
    </div>
    <div class="g8-col m4 g8-hide-small">
    <!--<p><span class="g8-padding-large g8-right"><b>Comments &nbsp;</b> <span class="g8-badge">2</span></span></p>-->
    </div>
    </div>
    </div>
    </div>
    <!-- END BLOG ENTRIES -->
    <?php endforeach; ?>

     

    <? echo $results->renderPager(array(
    'nextItemLabel' => "rückwärts",
    'previousItemLabel' => "vorwärts")); ?>
     
    //and now the same code again with "category=cars" replaced with "category=bikes"
     
    <?php foreach ( $results = $pages->find('id>1, template=templateblogpost, category=bikes, limit=5, sort=-postdate') as $post ?>
    <!-- Blog entry -->
    <div class="g8-card-4 g8-margin g8-white">
    <!--<img src="/g8images/bridge.jpg" alt="Norway" style="width:100%">-->
    <div class="g8-container">
    <h3><b><?= $post->title; ?></b></h3>
    <h5>Datum: <span class="g8-opacity"><?= $post->postdate; ?></span></h5>
    </div>
     
    <div class="g8-container">
    <p><?= $post->posteditor; ?></p>
    <div class="g8-row">
    <div class="g8-col m8 s12">
    <p>
    <a href="<?= $post->url; ?>"><button class="g8-button g8-padding-large g8-white g8-border"><b>Details lesen &raquo;</b></button></a>
    </p>
    </div>
    <div class="g8-col m4 g8-hide-small">
    <!--<p><span class="g8-padding-large g8-right"><b>Comments &nbsp;</b> <span class="g8-badge">2</span></span></p>-->
    </div>
    </div>
    </div>
    </div>
    <!-- END BLOG ENTRIES -->
    <?php endforeach; ?>
     
    <? echo $results->renderPager(array(
    'nextItemLabel' => "rückwärts",
    'previousItemLabel' => "vorwärts")); ?>

  17. 7 minutes ago, dragan said:

    Just use URL segments.

    Hi @dragan, I have read about url segments before but I have no idea how to implement it in my code above. Also I am not sure if url segments still work if new categories will be added by an end user of the cms (at the moment I just have the categories cars, bikes, planes, ...).

    Is there no easy way with a switch or if statement just to check what is the parent url segment (/categories/car/) -> return ... category=cars

    check case: /categories/bikes/ -> return ... category=bikes

    If I just wanted a working solution and would have 5 categories for example than I would just my code from above 4 more times to 4 new templates and all is fine (but bad practise because all code would be identical and only differ by one word (the category itself)

     


  18. Good morning everyone!

    I have a growing number of posts about cars, bikes, airplanes, etc. 

    The following code (below) just works fine and returns only the posts of the category=cars as I desired together with pagination.

    In my url I have for example /categories/cars/car1 or /categories/bikes/bike1

    I do want to filter my posts not only with ... category=cars ... but also with category=bikes or category=airplanes and at best:

    If my url is /categories/bikes/ then ... category=cars ... should be overwritten or replaced by ... category=bikes ... 

    If my url is /categories/airplanes/ ... then the filter should be ... category=airplanes ... (I know a work around by creating almost identical templates where I could just change the "category=cars" part of my code but that's comes of a prize by repeating a lot of identical code and is not a good habit). In the documentation I read something about the "has_parent" selector but I could not get to work it related to the urls mentioned above.

    <?php foreach ( $results = $pages->find('id>1, template=templateblogpost, category=cars, limit=5, sort=-postdate') as $post 😞?>
    <!-- Blog entry -->
    <div class="g8-card-4 g8-margin g8-white">
    <!--<img src="/g8images/bridge.jpg" alt="Norway" style="width:100%">-->
    <div class="g8-container">
    <h3><b><?= $post->title; ?></b></h3>
    <h5>Datum: <span class="g8-opacity"><?= $post->postdate; ?></span></h5>
    </div>
     
    <div class="g8-container">
    <p><?= $post->posteditor; ?></p>
    <div class="g8-row">
    <div class="g8-col m8 s12">
    <p>
    <a href="<?= $post->url; ?>"><button class="g8-button g8-padding-large g8-white g8-border"><b>Details lesen &raquo;</b></button></a>
    </p>
    </div>
    <div class="g8-col m4 g8-hide-small">
    <!--<p><span class="g8-padding-large g8-right"><b>Comments &nbsp;</b> <span class="g8-badge">2</span></span></p>-->
    </div>
    </div>
    </div>
    </div>
    <!-- END BLOG ENTRIES -->
    <?php endforeach; ?>
     
    <? echo $results->renderPager(array(
    'nextItemLabel' => "rückwärts",
    'previousItemLabel' => "vorwärts")); ?>
×
×
  • Create New...