texts: List all entries below top level 1 in a structure section (level 2 or 3 or 4 ...)

texts:
I have a structure section with 3 levels.
I d like to list all entries below 1st level.
I see ancestorDist or descendantDist but I m not sure it is what I need...
https://craftcms.com/docs/templating/craft.entries

I see I can select multiple levels:
{% set entries = craft.entries.section('library').limit(10).level(2,3) %}
but I d like something like:
{% set entries = craft.entries.section('library').limit(10).level(>1) %}


texts: How do I save a Plugin's date settings-field?

texts:
I've got a plugin with some custom settings, like this:

protected function defineSettings()
{
    return array(
                 'serviceendpoint' => array(AttributeType::String, 'required'=>true),
                 'passkey' => array(AttributeType::String, 'required'=>true),
                 'newregistrationdate' => array(AttributeType::DateTime, 'required'=>false),
                 );
}

Then I have a _settings template, which renders the form:

{{ forms.textField({
    first:        true,
    label:        "CRM Endpoint URL"|t,
    id:           'serviceendpoint',
    name:         'serviceendpoint',
    instructions: "The URL for the CRM service ."|t,
    value:        settings.serviceendpoint,
    autofocus:    true,
    placeholder: "https://example.com/api/...",
    errors:       settings.getErrors('serviceendpoint')
}) }}

{{ forms.textField({
    label:        "The service passkey"|t,
    id:           'passkey',
    name:         'passkey',
    instructions: ""|t,
    value:        settings.passkey,
    placeholder: "1234...",
    errors:       settings.getErrors('passkey')
}) }}

Val: "{{ dump(settings.newregistrationdate) }}"

{{ forms.dateField({
    label:        "New registrations after this date"|t,
    id:           'newregistrationdate',
    name:         'newregistrationdate',
    instructions: "Users registered after this date will get a welcome email"|t,
    value:        settings.newregistrationdate.date|default,
    errors:       settings.getErrors('newregistrationdate')
}) }}

The String-typed values are saved just fine. But the DateTime always comes back as false.

I've tried adding a prepSettings function, and doing:

 $settings['newregistrationdate'] = new DateTime($settings['newregistrationdate']['date']);

but it makes no difference.

What does prepSettings have to return for DateTime typed fields?


texts:
I am using the latest version of Craft CMS with Nginx server. My problem is, in my site settings i setup 4 websites that are as below:

German (de-de) [default]
German English (en-de)
Austria (de-at)
Austria English (en-at)

Now my primary goal, for now, is to redirect any user to the default (i.e. de-de) website. So if a client request for https://example.com, he will be redirected to https://example.com/de-de. If I try manually to access https://example.com/de-de, it works.
I tried different solutions from StackOverflow and StackExchange but none of them worked for me. Any help will be much appreciated. Thanks in advance. :)


texts: Render template from Module in twig template

texts:
I have been searching around SE and the web in general for an answer to this. There seems to be plenty of solutions but none appear to be working for me.

I have a simple module that has a variable that gets called from a twig template in order to render a form.

The problem is no matter what I do I cannot get the module to render the HTML from within its own /templates directory.

The variable code is:

$oldMode = \Craft::$app->view->getTemplateMode();
\Craft::$app->view->setTemplateMode(View::TEMPLATE_MODE_SITE);
$html = \Craft::$app->view->renderTemplate('../templates/_journey-planner.html');
\Craft::$app->view->setTemplateMode($oldMode);
return $html;

This is taken from the Craft docs. I have also used:

Event::on(View::class,
          View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS,
          function (RegisterTemplateRootsEvent $e) {
                $e->roots['journeyplannermodule'] = 'journeyplannermodule/src/templates';
            }
        );

Within the module's init() function (not sure if this is actually required or not).

What am I doing wrong and what do I need to do to simply display this template within the twig template?

I am calling the variable method with:
{{ craft.journeyPlannerModule.getJourneyPlanner }}

Craft Version: 3.2.0


texts: Using ImageOptimize plugin with Matrix fields

texts:
With the ImageOptimize plugin for Craft 3, you create an OptimizedImages field type and then assign that to the Field Layout of your chosen Asset Volume. As far as I can tell (I'm very new to Craft), this means that it won't work to add an Assets field inside a Matrix because it doesn't have the OptimizedImages field associated with it. (I've tried, and received Calling unknown method: craft\elements\Asset::optimizedImages())

Is anyone aware of a possible workaround? I'm guessing that something like Craft Neo, which allows you use existing fields in a Matrix, would be a solution, but at this early stage, there is no version of the plugin for Craft 3.

Thanks for any insight!


texts: Push Notification plugin will not send iOS alerts when Craft CMS devMode is set to false

texts:
The Push Notification plugin will send out alerts ONLY if devMode is set to true.

I can't leave my production environment in development mode so I'm trying to figure out why the alerts won't send when devMode is set to false.

I have checked the PushNotifications_PushService.php page and the logs will print out that Notified is 1 (which would be correct for my test). However, the alert never sends out. My phone never receives the alert.

My only assumption is that it deals with the APNSAdapter but that is coming from Sly/NotificationPusher. I've never worked with this class before so I'm not sure exactly how it works. Does anyone have any ideas what is going on?

UPDATE 1:

I am pretty sure the problem deals with the NotificationPusher class that the developer is importing. However, I'm not sure what is wrong with it.

See this: https://stackoverflow.com/questions/27611388/phonegap-pushplugin-with-notificationpusher-not-working-in-production

Here is an issue also posted on the NotificationPusher GitHub:
https://github.com/Ph3nol/NotificationPusher/issues/111

UPDATE 2:

Tested via command line using the following command:
./np push --certificate=/path/to/production_ck.pem apns deviceToken "Notification test"

This worked. No errors. Phone received alert.

Still not sure why it won't receive them from Plugin in Production Mode.

UPDATE 3:

I have placed log statements into the NotificationPusher class. I found no errors when comparing it to the "Dev" process.

I noticed when debugging the NotificationPusher project that it utilizes zendframework APNS to send the messages. My assumption is that the error must be somewhere within this project.

I found this: http://framework.zend.com/manual/1.12/en/zend.mobile.push.apns.html

In the first comment, he isn't getting any errors either but the alert is never getting to the device.

As far as the NotificationPusher project, I was able to determine that:

It is getting the device token and the message data
The response data is the same for both development mode and production mode. (However, the iPhone device never receives the alert message in production mode.) Still no error from code

Has anyone worked with the Zendframework? Any ideas what is going on?

UPDATE 4:

The only difference I have found so far is that the development mode uses the sandbox URL whereas the production mode uses the production mode.

What doesn't make sense is that I'm using my production certificate and it works on the sandbox URL but it doesn't work on the production URL.


texts: Setting up load balancing for Craft on Laravel Forge

texts:
I'm attempting to set up a load balancing set up on laravel forge for a craft site.
I have one server that is provisioned as a load balancer, two app servers both set up to server the same craft install (deployed from the same Git Repo) and one db server.

The two app servers are configured to use the db server in the env file. I have tested hitting both app servers by adjusting my host and can confirm that each loads the Craft site as expected. I've put up a firewall to only accept traffic on port 80 from the private IP of the load balancer.

My load balancing server is configured to network with the app servers. The load balancer is set up with SSL (let's encrypt).

The issue I'm seeing seems to be in the SSL redirect Laravel Forge sets up. After configuring SSL I get a bad gateway error when I load the site.
Here is my nginx config for the load balancer

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/mydomain.com/before/*;

# FORGE CONFIG (DO NOT REMOVE!)
include upstreams/mydomain.com;

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name mydomain.com;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/mydomain.com/774031/server.crt;
    ssl_certificate_key /etc/nginx/ssl/mydomain.com/774031/server.key;

    ssl_protocols TLSv1.2;

    charset utf-8;

    access_log off;
    error_log  /var/log/nginx/backtowork-ri.com-error.log error;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/backtowork-ri.com/server/*;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass https://1013240_app/;
        proxy_redirect off;

        # Handle Web Socket Connections
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

    }
}

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/mydomain.com/after/*;

if I adjust the config to listen on port 80 and 443 like so

server {
    listen 80;
    listen [::]:443 ssl;
    ...

I see a too many redirects error.

I'm really not sure what I'm doing wrong. Any one have any thoughts?


texts: MAMP: Craft can’t connect to the database with the credentials in craft/config/db.php

texts:
I'm using MAMP to setup a local environment for CraftCMS on Windows 10.

I have followed all necessary procedures and have my local host and my database setup but I'm still receiving the error mentioned above.

My db.php is shown as this:

 return array(

        // The database server name or IP address. Usually this is 'localhost' or '127.0.0.1'.
       'server' => 'localhost',

        // The name of the database to select.
        'database' => 'mycraft',

       // The database username to connect with.
       'user' => 'root',

       // The database password to connect with.
      'password' => 'root',

       // The prefix to use when naming tables. This can be no more than 5 characters.
      'tablePrefix' => 'craft',

 );

Even if i make a custom user or password I still get the error above when I try to connect to http://localhost:8888/admin

I've checked many times and all my credentials as well as my local host port is correct. Craft can clearly connect to host which is why I'm getting the error from craft but for some reason, despite the details in db.php being correct it cant connect to the database...

Anyone know what's going on?


texts: Digital Ocean: Dev + Production Droplets

texts:
I've been learning craft and want to setup a production & development environment. I've primary HTML CSS experience with limited backend or server related experience

One way I thought about doing this was setting up 2 separate droplets on Digital Ocean (w/ServerPilot) and copying digital ocean snapshots from the dev droplet to the production droplet.

Is this a feasible approach?
Does the license allow this if I don't map a domain to it and operate it as an IP address OR use an obscure term (staging etc.) in a odd domain (vs. sub-domain as mentioned in docs)?
Is there a better (noob-friendly, learnable) way to do this?

Thanks


texts: Workaround for deprecated regex pattern modifier in PHP 5.5.0 and up (10.10 Yosemite)

texts:
I'm relying on the Low Regex plugin to convert section handles from camelCase to lower-dash-case to use them in URLs, like so:

{section.handle|regex('/(^|[a-z])([A-Z])/e', 'strtolower(strlen("\\1") ? "\\1-\\2" : "\\2")',(section.handle))}

…and further, to convert the segment of the URL that contains the dash-separated section name to camel case, so I can work with it in my templates, like so:

{% set sectionHandle = craft.request.getFirstSegment() %}
{% set sectionHandleCc = sectionHandle | regex('/-([a-z])/e', 'strtoupper(strlen("\\1") ? "\\1\\2" : "\\2")',(sectionHandle)) %}
{% set section = craft.sections.getSectionByHandle(sectionHandleCc) %}

Now, OS X 10.10 Yosemite ships with PHP version 5.5.14 pre-installed and as of 5.5.0 the e-modifier for regex patterns is deprecated, so on my local machine I get this error and the site breaks:

I got in touch with the plugin author and he suggested removing the e-modifier, which seemed to work within the templates, but when I removed the modifier in the sections entry URL format the CP wasn't able to re-save my entries and I couldn't save new entries either.

The question that remains is: Is there a workaround using a different regex pattern or – and that would be my preferred scenario – is there an approach I didn't think of that allows me to omit the plugin dependency completely? I guess one option would be to keep the section handles all lowercase, but I'd like to have them dash-separated in the URLs.


texts: Prevent craftcms caching CMS page with dynamic template

texts:
I understood CraftCMS caching should exclude dynamic values, however I have a page built as an Entity within CraftCMS admin which {% include %}'s a template with a form.  The templates dynamic form values are somehow being rendered with cached values.

The included template form uses dynamic values from e.g. {{ craft.session.getFlash(key, '') }} which are getting cached by CraftCMS causing the form to render with someone else's session values.

Neither the Entity nor template had {% cache %} flags, and I've tried various cache settings to try and prevent such as {% cache unless craft.session.hasFlash('key') %} within the form template, and before the {% include %} within the Entity page, however the template is still rendered with cached form values.

This is CraftCMS 2.4 with no custom caching plugins, using a Redis cache store and default Craft caching config values.

How can I prevent this? Thanks!


texts: Is it possible to delete entries directly from the 'All entries' listing in the control panel?

texts:
I have a couple of Channels with news entries imported from different RSS feeds. A lot of these entries have a similar topic, so it would be very nice if these entries could be deleted from the 'All entries' listing in the control panel. That way, entries from different sections can be compared by title, and easily deleted.

This is possible when using the listing of a single Channel, but not the 'All entries' listing. Is this still possible somehow.

Combining the entries in a single Channel is not an option unfortunately due to different fields and needs per RSS feed.


texts:
Is it possible to output a getSegments() array in a template to then run conditions on?

I can output one segment fine using getSegment(), but if I try to select one or more segments using getSegments() it outputs 'Array'.

Thanks in advance for any help.


texts: using cycle with unknown number of entries

texts:
I'm using cycle to open and close a div for a row of content. It works great when there are more than a certain number of entries - in this case 4, but doesn't work when there are fewer than that. Is there a way to make this work so it always closes the div even if there are fewer entries than specified in the code?

{{ cycle(['
', '', '', ''], loop.index0) | raw }}
... stuff....
{{ cycle(['', '', '', '
'], loop.index0) | raw }}


texts: What's the best way to make sure external URLs aren't interpreted as relative links?

texts:
I have a field where the client can enter a URL, and then that field's value is put into the 'href' of a link in the template. The client will sometimes prepend it with "http://", sometimes with "www.", and sometimes with nothing. Unless it's prepended with "http://" or "https://", the link is interpreted as relative and tries to go to "http://mysite.com/www.otherlink.com", which is obviously not what I want.

What's the best way of automatically handling different URL formats?


texts:
I'm trying to create a podcast feed with Craft, and I seem to have everything working... except I can't find out how to grab the length of an audio file dynamically. I can get the filesize in bytes, and if it's an image asset you can get width... but there doesn't seem to be a way to get the play-time for an audio file; which is needed for the <itunes:duration> tag.

Anyone know how to do this?


texts: Limit characters in redactor wysiwyg field

texts:
I'm trying to limit the amount of characters by adding the 'limiter' plugin to the redactor field which can be found here:

http://imperavi.com/redactor/plugins/limiter/

I've added the limiter.js file to my /craft/app/resources/lib/redactor/plugins folder.

Next I changed the Standard.json in /craft/config/redactor/Standard.json to

{
 focus: true,
 limiter: 20,
 buttons: ['html','formatting','bold','italic','unorderedlist','orderedlist','link','image','video'],
 plugins: ['fullscreen','limiter'],
 toolbarFixedBox: true
}

Unfortunately it doesn't work. Anybody a good suggestion how I can fix this easily. Thanks!


texts: Where can I find someone to help build my Craft website?

texts:
We're looking to hire a talented developer to help us complete and/or maintain a project in Craft.

We'd like to hire them for a limited contract, or possibly full-time employment.

Where can I find a person or agency to work on my Craft project?


texts: Find Related Entries with Identical Tags

texts:
I'm trying to show related entries for a single item.

I want to look up a specific tag(s), and search for any entries that share the same tag(s) then display those related items.

I've read through the documentation and searched around but couldn't find a solution.


texts:
I'm having problems with Worldpay and their notorious dislike of 302 redirects with the payment response. I remember this problem last year and Luke fixed it but it seems to have returned.

Within Commerce_PaymentsService there is code targeting Worldpay and some other gateways, around line 15 in the latest version. I believe that was to avoid the 302 redirect problem from last year.

What I've done is added code to log where the script is getting to, and it seems it never even reaches this code. You can see from the sample below

    if ($success && $transaction->status == Commerce_TransactionRecord::STATUS_SUCCESS)
    {
        CommercePlugin::log('Commerce_PaymentsService line 814', LogLevel::Info, true);
        craft()->commerce_orders->updateOrderPaidTotal($transaction->order);
    }
    CommercePlugin::log('Commerce_PaymentsService line 817', LogLevel::Info, true);

    // For gateways that call us directly and usually do not like redirects.
    // TODO: Move this into the gateway adapter interface.
    $gateways = array(
        'AuthorizeNet_SIM',
        'Realex_Redirect',
        'SecurePay_DirectPost',
        'WorldPay',
    );

The line saying 'Commerce_PaymentsService line 817' is not being reached. I've currently following the trail and am several functions within Commerce_OrdersService applying the same metho to figure out what's happening.

Does anyone know of a change in the way Commerce works that would bypass this Worldpay test?

I made a support request yesterday, but no response yet, which is why I'm on here.

UPDATE: the latest version of Craft Commerce has changed things with Customer Emails. I've got some deprecated notices in the control panel. I'm wondering whether there is an email problem which is stopping things proceeding.

UPDATE 2: rolled back two versions before the email change and it's still broken. I've noticed that when you update an order's status in the control panel the email is not being sent and a popup error saying 'Undefined' is being shown. There's nothing in any of the logs so it looks like more trawling through Craft Commerce. Test emails from Craft work fine, and the email template is fine when viewed on the front end.

UPDATE 3: Removing the emails from the order statuses allows the order status to be updated fine. So there is definitely a problem with the emails. Then I've updated to use a test email containing nothing but static text - that processes, send and even redirects from Worldpay fine. It's my order email template.


texts:
I wonder what structures are since everybody writes about it here. But I can only finde one tiny sentence in the official docs:

  «Used when entries do have an inherent relationship with each other,
  unlike Channels. They are both sortable and hierarchical.»

Is there somewhere a bit more of a real world explenation/example on when/why/how to use this «structure» thing?


texts: Display entries sharing the same nested category on an entry page

texts:
I'm trying to show the other entries assigned to the same nested category (on an entry template)
but get an error if I use .last() which I was hoping would show the nested category assigned entries (and not all assigned to all levels of the same category,

Any ideas?

{# set the category group #}
{% set categoryGroup = craft.categories.group('products') %}

{% set entries = craft.entries.relatedTo(categoryGroup)  %}

{# only show entries assigned to the same nested category #}
{% for sameCat in entries.last()  %}
    <p>{{ sameCat.title }}</p>
{% endfor %}

{# note: using .last throws error – Impossible to access an attribute ("title") on a string variable ("1").
 #}


texts: Dynamically load either standard res or hi-res background image

texts:
I am currently dynamically loading a background image using the style tag:

<li style="background-image: url({{ project.portfolioImage.first().url }})">

I want to add support for retina screens, so I want to also upload a hi-res version as well as the standard one and serve whichever is applicable.

Can I use {% includeHiResCss %} to do that?


texts: We will be creating a website for a large clinical trial. The catch is that this trial will have study sites in many different areas of the world. We want to appeal to use user depending on their demographic. For example, when a user from one of our Thailand sites visits the website, we want them to see photos of Asian study participants (from photos we provide). Is this a possibility? It would sort of be like text translation but with photos instead.


texts: Rich Text Field is returning an empty object over api of plugin json_expand

texts:
Is anybody using the json_expand plugin for API functionality?
For the entry type Rich Text Field its just returning an empty object.

This is my json_expand endpoint:

{% header "Content-Type: application/json" %}
{% set utensils = craft.entries.section('utensils').find('') %}
{{ utensils | json_expand | raw  }}

It's returning everything except that Rich Text field which just returns this:

"utensil_textbox": {}


texts:
I am a little bit confused by the documentation about assets. It says that paths are relatives from the directory that holds the index.php file.

Now, I am working on multisite, with the following folders:
    craft/web/site1/
    craft/web/site2/

Is it possible to have:
    craft/assets/site1/
    craft/assets/site2/

Or:
    craft/web/site1/assets/
    craft/web/site2/assets/


texts: Allowing a new locale to fallback on content from a default locale?

texts:
I am setting up a localized site that defaults to English (en_us). Alternate locales will have URLs such as example.com/fr

I would like to ensure that users browsing the French website don't accidentally end up back on the default locale. My problem is that some sections will not target the French locale but I would still like the URL to display the default, English content with the /fr/ URL.

If I uncheck targeting for that locale in my section settings, then browse to the entry (example.com/fr/section/entry) I get a 404. How can I display the default English entry content at that URL?