Pode
ReleasesGitHub
  • Introduction
  • Getting Started
    • Installation
    • CLI
    • Docker
    • Frontend
  • Tutorials
    • Routes
  • Functions
    • Attach
    • Engine
    • Listen
    • Server
    • Status
    • View
Powered by GitBook
On this page
  • Description
  • Examples
  • Parameters
  1. Functions

View

PreviousStatus

Last updated 6 years ago

Description

The view function allows you to render any of the view files that you place within the /views directory. When you call view, Pode will automatically look within this directory.

Pode uses a View Engine to either render HTML, Pode, or other types. Default is HTML, and you can change it to Pode by using the function.

Examples

  1. The following example will render the index.html view when you navigate to http://localhost:8080:

     Server {
         listen *:8080 http
    
         route get '/' {
             view 'index'
         }
     }
  2. The following example will render the index.pode view when you navigate to http://localhost:8080:

     Server {
         listen *:8080 http
         engine pode
    
         route get '/' {
             view 'index'
         }
     }
  3. The following example will render the index.pode view when you navigate to http://localhost:8080, it will also supply dynamic data - in this case, the current date:

    The dynamic data can be used in your pode view via $($data.date)

     Server {
         listen *:8080 http
         engine pode
    
         route get '/' {
             view 'index' -d @{ 'date' = [DateTime]::Now }
         }
     }

Parameters

Name

Type

Required

Description

Default

Path

string

true

The path to the view to render, relative to your /views directory

null

data

hashtable

false

A hashtable of dynamic data that will be supplied to .pode, and other third-party template engines

@{}

engine