Right now I have a loop in the view that displays a brief description of topics:
example code:
<div id="menu">
<ul>
{% for item in topics %}
<li>
<img src="img/{{item.name}}_ico.png" alt="{{item.name}}" />
<h2>{{item.heading}}</h2>
<p>{{ item.detail|safe }}</p>
</li>
{% endfor %}
</ul>
</div>
The above code displays an icon – a heading and some text for several items.
Since these topics never change and are only updated by the devs, I created a dictionary in the controller that contains all this content..
topics= [
{'name': 'alert',
'heading': "Maintain attention",
'detail': 'Keep your students involved, alert and attentive during class with closed questions about the current subject.'},
{'name': 'time',
'heading': 'Instant feedback',
'detail': 'Save precious time and avoid checking quizzes!<br />studyWise© check them instantly, providing you with results.'},
{'name': 'reward',
'heading': "Reward students",
'detail': 'Motivate students to participate and learn by rewarding good work with positive feedback.'},
{'name': 'money',
'heading': 'Save on expenses!',
'detail': 'Why spend money buying similar gadgets or subscriptions?<br />Use studyWise© free of charge now.'},
{'name': 'cell',
'heading': 'Accessible',
'detail': 'Works with any smartphone, laptop or tablet.<br />No installation required.'},
{'name': 'share',
'heading': 'Share with colleagues',
'detail': 'Share topics, quizes or course statistics with colleagues.<br />See how your assistants are doing.'},
{'name': 'statistics',
'heading': 'Statistics',
'detail': 'Get helpful info about your students understanding of the learning material today.'}
]
What I am wanting to do is adhere to MVC principles and keep the code clean.
Should I move this dictionary to a ‘model’ file?
Will that affect performance?
Thanks
These topics should be database records and you should just query them when you want to use them. Depending on the framework you are using, you might not even have to change your template.
In Django you would have :
Whether they change often or not doesn’t matter in that regard.
I honestly think that the performance impact is not a concern you should have here.