Snippet: cwsoft-anynews

cwsoft

#127
@marmot: Your code example will work after two small updates:

1. month index needs to be reduced by 1 as date("m") starts with 1 but Twig arrays starts with 0
2. template TIMESTAMP fields are already converted as datestring using settings in language file, this needs to be removed from include.php to allow conversion of the numeric TIMESTAMP in Twig using the date modifier

Changes in template:

<div class="mod_anynews">
<h2>{{ lang.TXT_HEADER }}</h2>

{% if newsItems %}
{% set germanmonth = ["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"] %}

<ul>
{% for news in newsItems %}
<li>{{ germanmonth[news.PUBLISHED_WHEN | date("m") - 1] }}
{% endfor %}
</ul>

{% else %}
{{ lang.TXT_NO_NEWS }}
{% endif %}

</div>


Changes in include.php
Remove the date conversion from the inlcude.php to look as follows:


'POSTED_WHEN'     => $row['posted_when'],
'PUBLISHED_WHEN'  => $row['published_when'],
'PUBLISHED_UNTIL' => $row['published_until'],
'DATE_FORMAT'     => $LANG['ANYNEWS'][0]['DATE_FORMAT'],


Will most likely change this with a future release. Either by adding new fields like POSTED_WHEN_TS (timestamp) and extra field DATE_FORMAT to ensure backward compatibility with customized templates.

Cheers

Argos

Thanks, but doesn't work. There is no output for the month, only the day.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

marmot

Hi,
Quote from: Argos on June 08, 2013, 01:31:10 AM
Thanks marmot. It doesn't work however.
now it does (just a missing "[" in line 1: {% set germanmonth = ["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"] %}
{% for news in newsItems %}
<div class="twig_block">
    <div class="twig_date">
        <div class="twig_day">{{news.PUBLISHED_WHEN|date("j")}}</div>
        <div class="twig_month">{{germanmonth[news.PUBLISHED_WHEN|date("m")]}}</div>
   </div>
    <div class="twig_title"><a href="{{news.LINK}}">{{news.TITLE }}</a></div>
</div>
{% endfor %}


regards

Argos

Thanks marmot. It doesn't work however.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

marmot

#123
Hi,

Quote from: Argos on June 05, 2013, 05:45:13 PM
I almost got it, except that the month is in English, and doesn't follow the locale set in the admin. How can I change that?
maybe this way:

find fixed code below


regards

Argos

#122
I'm sure Twig is great for coders, but I'm not a coder  :|

With my limited PHP skills I can tweak WB code a bit sometimes, and with lots of trial & error and lots of help from others I sometimes succeed. But in fact I often don't have clue what code does, and I cannot create code myself. So for me Twig just adds another layer of mumbo jumbo LOL. Don't take it personally, your work to modernize and maintain the modules and snippets is much appreciated!

So what a simple line of code is for you, is an impossibility for me :cry:

But if you help me out here, I can finish the client site today or tomorrow, and I promise after that I'll check out the things we discussed before. So this week. Deal?  :roll:
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

cwsoft

#121
Quote from: Argos on June 05, 2013, 11:27:33 PM
Doesn't this Twig stuff just add a big layer of complexity to this snippet?
Not really. Date formating is more a shortcoming of PHP, which was improved in PHP 5.x series.

Twig provides a lot of freedom compared to the previously used template. About all requested features since introduction of Twig could be realized by a customized Template, where before people had to hack the Anynews code itself.

Creating an array with month names is a just one code line in Twig shown in the documentation I linked before , so I don't see the big complexity :wink:

Cheers

P.S.: guess you had no time yet to check the modifications I applied based on your request some weeks ago - or :-)

Argos

Way over my head...  :cry:

Doesn't this Twig stuff just add a big layer of complexity to this snippet?
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

cwsoft

#119
Quote from: Argos on June 05, 2013, 05:45:13 PM
I almost got it, except that the month is in English, and doesn't follow the locale set in the admin. How can I change that?
For this task, the datetime filter is used. However, it would need to be activated.

Another option is to create an array in the Twig template holding the Dutch month names from Jan to Dec and use date function to return the month as integer value 1-12 as index for the array. For details see the excellent Twig online help.

Cheers

Argos

#118
Quote from: cwsoft on June 05, 2013, 12:56:09 PM
@argos: Date formats can be defined via Twig date function and a modified Anynews template. If default date filters provided by Twig are not sufficient for you, one can code it's own Twig function or extension to transform whatever is needed.

I almost got it, except that the month is in English, and doesn't follow the locale set in the admin. How can I change that?

This is my code:

{% for news in newsItems %}
<div class="twig_block">
   <div class="twig_date">
       <div class="twig_day">{{news.PUBLISHED_WHEN|date("j")}}</div>
       <div class="twig_month">{{news.PUBLISHED_WHEN|date("M")}}</div>
   </div>
   <div class="twig_title"><a href="{{news.LINK}}">{{news.TITLE }}</a></div>
</div>
{% endfor %}


And I added these classes:
.twig_block {display:block;clear:both;width:100%;margin-bottom:10px;min-height:50px;overflow:auto;}
.twig_date {width:20%;min-width:35px;float:left;}
.twig_date .twig_day {background:#a8d591;color:#333;font-weight:bold;text-align:center;font-size:110%;border-radius:4px 4px 0 0;}
.twig_date .twig_month {background:#5c9d3b;color:#fff;text-align:center;border-radius:0 0 4px 4px;font-size:70%;text-transform:uppercase;}
.twig_title {float:right;width:75%;margin-top:-2px;}


This looks like the schreenshot. While the abreviation for June is "Jun" in both English and Dutch, I tested it with "F" instead of "M", and it shows the English "June" instead of the Dutch "Juni".
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

cwsoft

#117
@argos: Date formats can be defined via Twig date function and a modified Anynews template. If default date filters provided by Twig are not sufficient for you, one can code it's own Twig function or extension to transform whatever is needed.

Cheers

Argos

Is it possible to bypass the default date format set in the Admin Settings, just for the AnyNews function?

I'd like to add classes to the date elements and style the date output, so I can create date "icons" like you see for example on http://code.garyjones.co.uk/style-post-info?
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Argos

Wrong assumption. I just didn't have the time to test yet. Especially because I uninstalled the latest version and went back to a previous one that I knew worked fine. Had to continue with this client site. But I will try and test the latest version on my test site asap.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

cwsoft

@argos: Guess no news/feedback are good news and your issues are solved with the infos given two posts before. In other words I assume the reported issue is fixed.

cwsoft

#113
@argos: Did removing the quotes around the cwsoft-anynews droplet parameter solve your issues with the droplet call?
If not what cwsoft-anynews version and WB version are you using?

cwsoft

#112
Hi Argos,

Quote from: Argos on May 10, 2013, 03:03:21 PM
It seems the section_id and page_id parameters don't work. I have this droplet, which should show the news from news section ID 27, but instead it shows the "no news available" line.

[[getNewsItems?group_id=27&group_id_type='section_id']]
Anynews droplet parameters needs to be passed over without quotes (see section_id):
[[getNewsItems?group_id=27&group_id_type=section_id]]

Quote from: argosAnd also the regular code calls don't seem to work with page_id and section_id...
Can't confirm this. Code inside a code section works for me with cwsoft-anynews 2.8.2 and the example code at GitHub.

If you can't get it working, try it first without the other parameters (just group_id and group_id_type) and double check group_id are right. Hope this helps.

Cheers

P.S.: next version will manage unquoted and quoted droplet parameters to remove this possible error source :wink:

Argos

#111
It seems the section_id and page_id parameters don't work. I have this droplet, which should show the news from news section ID 27, but instead it shows the "no news available" line.

Quote[[getNewsItems?group_id=27&max_news_items=5&max_news_length=80&display_mode=50&not_older_than=360&group_id_type='section_id']]

And this (use page ID 9) doesn't work either:
Quote[[getNewsItems?group_id=9&max_news_items=5&max_news_length=80&display_mode=50&not_older_than=360&group_id_type='page_id']]

And also the regular code calls don't seem to work with page_id and section_id...
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

cwsoft

#110
Hello,

cwsoft-anynews v2.8.2 stable is available at GitHub and the WebsiteBaker Add-ons repository.

Updates since last release:
- fixed regression with multiple Anynews Droplet calls at one page/section
- fixed two possible PHP notices/warnings

cwsoft

cwsoft

Hi,

Quote from: StephanLE on February 10, 2013, 07:22:23 PM
I chose option 2. It now works as it should.
Glad it worked. I prefer this option too, as it is more obvious for the reader.

Cheers

StephanLE

Thank you

You heard me all right.
I chose option 2. It now works as it should.

cwsoft

#107
Hi,

Quote from: StephanLECan one code section also pass parameters?
Note quite sure I really understand what you are after, but lets try.

Option 1: requires cwsoft-anynews >= v2.8.0

if (function_exists('getNewsItems')) {
   echo getNewsItems(array(
    'max_news_length' => 30,
    'display_mode' => 3,
   ));
}


Option 2: requires cwsoft-anynews >= v2.8.0

if (function_exists('getNewsItems')) {
  $options = array(
    'max_news_length' => 30,
    'display_mode' => 3,
  );
 
   echo getNewsItems($options);
}


The old $parameter = VALUE (displayNewsItems) just translates into 'parameter' => VALUE (getNewsItems).

Tip:You could also create a Droplet and use [[getNewsItems?parameter1=VALUE&parameter2=VALUE2]] in a WYSIWYG section or your template, following the steps explained in the README.

Cheers

StephanLE

Can one code section also pass parameters?
if (function_exists('getNewsItems')) {
    echo getNewsItems();
}

If so how?
I do not get it out the embed.
$max_news_length = 30,
$display_mode = 3,

cwsoft

#105
Hi,

Quote from: dimlazThanks for the help, it works now.
I thank you for your example allowing to show the more flexible configuration in a real world example.

To achieve what you want with the old displayNewsItems function, one would have needed to provide ALL parameters in right order, even though one needs to change only the first ($group_id) and last parameter ($group_id_type). Sometimes I wish PHP would be more similar to Python.

Cheers

dimlaz

 :-)
Great,

Thanks for the help, it works now.


cwsoft

#103
Hi,

Quote from: dimlazit seems that the section_id, group_id does not work.
Your code won't work. The parameter 'section_id' is no valid Anynews parameter. Your code example sets  'group_id' = 0 (DEFAULT), which outputs news from ALL groups available.

If you want to limit Anynews output to a given section, you need adapt yor config array as follows:


$config = array(
 'group_id' => 8,
 'group_id_type' => 'section_id',
);


Details about the supported Anynews parameters are given at GitHub.

Cheers

P.S.: Nice to see people already start using the new syntax :wink: