style php results in html and css

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
rwahdan
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Aug 22, 2017 7:11 am

Mon Nov 20, 2017 10:50 pm

Hi,

I have a php code that lists folders and files but it is listed down each other. I would like to make them look as if they are window style folder/file structure. Could someone guide me how to do that or if there is a tutorial about that.

Code: Select all

foreach($allFiles as $value)
{
		$displayName = substr($value, $rootLen + 4);
		$fileName    = substr($value, 3);
		$linkName    = str_replace(" ", "%20", substr($value, $pathLen - 9));
		if (is_dir($fileName)) {
			echo prePad($level) . $linkName . "<br>\n";
			myScanDir($fileName, $level + 1, strlen($fileName));
		} else {
			echo prePad($level) . "<a href=\"" .  $linkName . "\" style=\"text-decoration:none;\">" . 			$displayName . "</a><br>\n";
							}
		}
thanks.

chorn
php-forum Active User
php-forum Active User
Posts: 411
Joined: Fri Apr 01, 2016 2:18 am

Tue Nov 21, 2017 1:41 am

use TWIG to output your results as HTML.

rwahdan
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Aug 22, 2017 7:11 am

Tue Nov 21, 2017 1:51 am

chorn wrote:
Tue Nov 21, 2017 1:41 am
use TWIG to output your results as HTML.
What is that and how to use it?

chorn
php-forum Active User
php-forum Active User
Posts: 411
Joined: Fri Apr 01, 2016 2:18 am

Tue Nov 21, 2017 2:56 am

just google for TWIG. it has a tutorial.

User avatar
Strider64
php-forum Active User
php-forum Active User
Posts: 314
Joined: Sat Mar 23, 2013 8:24 am
Location: Livonia, MI
Contact:

Tue Nov 21, 2017 4:59 am

Twig (https://twig.symfony.com/) or Smarty (https://www.smarty.net/) -> I use Smarty. Templating makes it easier to develop secure pages and give people with little programming to help with the design portion of the website.

Here's just a small example of what I mean taking from my cms template ->

Code: Select all

{* Create a CMS Display using Smarty *}
{nocache}
    {foreach $content as $thread}
        {* Show only left or right column posts depending on column position *}
        {if $thread.column_pos === $column}
            <article class="cms">
                <h2>{$thread.heading|escape}</h2>
                <h3 class="subheading">Created on {$thread.date_added} by {$thread.author|escape}</h3>
                <figure class="imageStyle">
                    <img src="{$thread.image_path}" alt="{$thread.heading|escape}">
                    <figcaption>&nbsp;</figcaption>
                </figure>
                <p>{$thread.content|escape}</p>

                {if $login_status && ($online_id === $thread.user_id)}
                    <div class="system">
                        <a class="edit" href="edit/{$thread.id}">Edit</a>                
                        <a class="delete" href="delete_page.php?id={$thread.id}" onclick="return confirm(\'Are you sure you want to delete?\')">Delete</a>
                    </div>
                {/if}

                <br>
            </article>
        {/if}
    {/foreach}
{/nocache}
Most people with some programming know about if statements and loops, but this example probably has most "programming code" in my templates. They don't need to know how to read/write to Database, use Object-Oriented Programming or any other complicated programming code.
Life is a fig newton of your imagination! https://www.pepster.com/index

Post Reply