I'm using Symfony 3.4 and this bundle https://github.com/hautelook/AliceBundle
This is my YAML file
AppBundle\Entity\Product:
template_product (template):
unit: !php/const AppBundle\Entity\ItemInterface::UNIT_PCS
product_teeth_{1} (extends template_product):
name: Răng sứ kim loại Mỹ ( BH 3 năm )
price: 1500000
categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
storeItems: ["@store_product_<current()>_1", "@store_product_<current()>_2"]
product_teeth_{2} (extends template_product):
name: Răng sứ Vita Đức ( BH 4 năm )
price: 1800000
categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
storeItems: ["@store_product_<current()>_1", "@store_product_<current()>_2"]
product_teeth_{3} (extends template_product):
name: Răng toàn sứ Zirconia ( CAD/CAM ) ( BH 7 năm )
price: 3900000
categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
storeItems: ["@store_product_<current()>_1", "@store_product_<current()>_2"]
product_teeth_{4} (extends template_product):
name: Răng sứ Titan ( BH 5 năm )
price: 2400000
categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
storeItems: ["@store_product_<current()>_1", "@store_product_<current()>_2"]
product_teeth_{5} (extends template_product):
name: Răng toàn sứ Full Zirconia ( CAD/CAM ) ( BH 10 năm )
price: 4400000
categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
storeItems: ["@store_product_<current()>_1", "@store_product_<current()>_2"]
product_teeth_{6} (extends template_product):
name: Răng toàn sứ Lava Plus - Ceramay (BH 20 năm)
price: 1200000
categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
storeItems: ["@store_product_<current()>_1", "@store_product_<current()>_2"]
AppBundle\Entity\CategoryProduct:
template_category_product (template):
id: <(substr(md5(uniqid(rand(), true)), 0, 18))>
template_category_1 (template, extends template_category_product):
category: "@category_product"
template_category_2 (template, extends template_category_product):
category: "@category_product_1"
category_product_{1..3}_1 (extends template_category_1):
item: "@product_teeth_<current()>"
category_product_{1..3}_2 (extends template_category_2):
item: "@product_teeth_<current()>"
AppBundle\Entity\StoreProduct:
template_store_product (template):
id: <(substr(md5(uniqid(rand(), true)), 0, 18))>
template_store_1 (template, extends template_store_product):
store: "@store_dentist_1"
template_store_2 (template, extends template_store_product):
store: "@store_dentist_2"
store_product_{1..3}_1 (extends template_store_1):
item: "@product_teeth_<current()>"
store_product_{1..3}_2 (extends template_store_2):
item: "@product_teeth_<current()>"
The issue is, as you see these lines. They repeat multiple times:
categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
storeItems: ["@store_product_<current()>_1", "@store_product_<current()>_2"]
I don't know how to pass the <current()>
to the template to reduce lines.
Can anybody let me know how to do it?
Is there any way to solve my issue?
I'm not stuck but try to do best practice DRY in YAML when using fixtures library
I have the answer after trying some solutions.
The
current()
should be put at the endFor example the category should be like that:
and the product