Skip to content

Working with ghost

SilverEngine edited this page Jan 12, 2018 · 6 revisions

Ghost Template engine

Functions

Helpers

Route

<a href="{{ route('home') }}"></a>

url

<a href="{{ url('/home') }}"></a>

lang

{{ lang('master.title') }}

or

{{ $data->title ?: 'empty' }}

Debug

dump and die

{{ dd($test) }}

not dump and die

{{ ndd($test) }}

Statments

if if else else

example

#if(true)
<p>is true</p>
#else
<p>is not true</p>
#endif

Loops

#foreach($item as $row) 
  {{ $row->id }}
#endforeach 
#for($i=0; $i <= 10; $i++)  
 ... your code here ...
#endfor 

Caller files

App\Views\welcome.ghost.php

{{ extends('layouts.master') }}

#set(content)

   {{ include('includes.navbar') }}
   Welcome to SilverEngine
   <!-- {{ component('comments') }} -->
#end

Extend layouts

App\Views\extends\master.ghost.tpl

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="styles.css">
</head>
<body>
   #block(content)
</body>
</html>

Includes

App\Views...\sidebar.ghost.tpl

<div class="sidebar">
   <ul>
      <li><a href="#">Home</a></li>
   </ul>
</div>

Components

Components provide direct access to the model on dynamical way in controller use

View::make('...')->withComponent('name');

App\Views\components\comments.ghost.tpl

<div class="comments">
   <ul>
      #foreach($example as $data) 
        <li>{{ $data->title }}</li>
      #endforeach
   </ul>
</div>
Clone this wiki locally