본문 바로가기

블록체인 기반 핀테크 및 응용 SW개발자 양성과정 일기

nunjucks 정리 if, for문 % 변수, 배열, 요소

반응형

 nunjucks 

 

 

Nunjucks의 변수 {{ }}

nunjucks에 건네주는 쪽에서 {{변수}} 를 넣어 줘야 한다.  

 

 

 

 

if, else, endif 

 

프로그래밍에 사용할 연산자를 사용할 경우 {% %} 을 사용한다. 

 

{% for [변수] in [배열]}

{{[변수],[요소]}}

{% endfor %}

 

 

 

block, endblock

include와 같은 개념

 

A.html 

{% block content %} {% endblock %}

 

B.html

{% extends "A.html" %}

{% block content -%}

(B.html에서만 보여줄 내용들 ㅇㅇㅇㅇㅇㅇ) 

{% endblock %}

 

-> A.html 의 블록 부분에 B.html에서 보여줄 내용들이 보이게 된다. 

 

 

 

 

set 

설정에 사용하는 거

 

set title = "hello" 라고 하면 브라우저 창의 title 이 hello가 된다. 

 

 

 

for 

{% for item in sequence %}

(반복할 내용...) - itme의 값은 반복문마다 다르다. 

{% endfor %}

 

endfor문은 {% endif %}처럼 그냥 닫는 문임으로 꼭 써주기 

 

 

그 외 

 

 

value로써 {{}}를 사용할 경우, "" 안에 넣어줘야 함. 

<input name="name" value="{{name}}"

 

 

 

 

velog.io/@pkbird/Nunjucks-basic

 

Nunjucks 정리

Nunjucks의 완전 기초적인 기능만 정리해보았다.

velog.io

https://mozilla.github.io/nunjucks/templating.html

 

Nunjucks

Templating This is an overview of the templating features available in Nunjucks. Nunjucks is essentially a port of jinja2, so you can read their docs if you find anything lacking here. Read about the differences here. User-Defined Templates Warning nunjuck

mozilla.github.io

 

반응형