adportal
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v433View latest version
This document explains how to use the component system for building templates in the DEV Partner Portal application.
The component system allows you to:
- Break down complex HTML templates into smaller, reusable components
- Pass parameters to components
- Use conditional logic within templates
- Maintain consistent styling and behavior across the application
/views
/components
/layout # Page layout components (header, footer)
/ui # UI elements (section cards, message boxes)
/forms # Form-related components
/uploadcare # Uploadcare-related components
/templates # Page templates that use components
To include a component in a template, use the following syntax:
{{> components/path/to/component param1="value1" param2="value2"}}
For example:
{{> components/layout/header title="My Page" subtitle="Welcome"}}
You can use conditional logic in your templates with the following syntax:
{{#if condition}} <!-- Content to show if condition is true --> {{#else}} <!-- Content to show if condition is false --> {{/if}}
You can also check for equality:
{{#if type == "success"}} <!-- Content for success type --> {{#else}} <!-- Content for other types --> {{/if}}
Component-specific styles are organized in the following structure:
/public/css
/components # Component-specific styles
section-cards.css
uploadcare-custom.css
forms.css
continue-page.css # Page-specific styles that import component styles
To create a new component:
- Create an HTML file in the appropriate subdirectory under
/views/components/ - Use
{{paramName}}syntax for parameters that should be replaceable - Use
{{#if condition}}for conditional content - Add component-specific styles to a CSS file in
/public/css/components/
<!-- /views/components/ui/alert.html --> <div class="alert alert-{{type}}"> {{#if title}} <h4 class="alert-title">{{title}}</h4> {{/if}} <p class="alert-message">{{message}}</p> </div>
Usage:
{{> components/ui/alert type="warning" title="Attention" message="This is important"}}
- Keep components small and focused on a single responsibility
- Use consistent naming conventions for components and parameters
- Document component parameters at the top of the component file
- Organize related components in subdirectories
- Use conditional logic for variations rather than creating multiple similar components
- Extract repeated patterns into components
- Use CSS classes for styling rather than inline styles